1

I am a newbie in Drupal, I have a table in a drupal database. I wanted to query all the content of it and display in a tabular format. Whenever I execute the query the link directs me to the blank page and nothing appears. I have attached the PhP code for the reference. Any help will be highly appreciated.

   <?php
  $header = array('Name', 'Age', 'Sex','University');
  $rows = array();

  $sql = 'SELECT Name, Age, Sex,University FROM {data_pulling} ORDER BY Name';
  $res = db_query($sql);
  while ($row = db_fetch_array($res)) {
    $rows[] = $row;
  }

  print theme('table', $header, $rows);
?>
4
  • a blank page usually means that you had a PHP error of some sort. Commented Jan 13, 2013 at 9:19
  • Exactly I view the PHP error it complains about this, Fatal error: Call to undefined function db_fetch_array() in /var/www/drupal/modules/php/php.module(80). Any idea ? Commented Jan 13, 2013 at 10:05
  • which version of Drupal are you using. dp_fetch_array was removed from Drupal 7 because there is a new database API. Commented Jan 13, 2013 at 10:40
  • I am using drupal 7, yes I find out recently that db_fetch_array was not there in the new API of Drupal 7. Thank you very much for your suggestion. :-) Commented Jan 13, 2013 at 10:51

1 Answer 1

4

At a guess you're using Drupal 7 but are trying to use API functions from Drupal 6.

Try this

foreach ($res as $row) {
  $rows[] = (array) $row;
}

print theme('table', array('rows' => $rows, 'header' => $header));

Have a look at the docs for db_query and theme_table for more information

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.