Your Ad Here

Posted By

theroamingcoder on 11/30/09


Tagged

mysql table query drupal


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

spf13


Display database query (MySQL / Drupal 5.x)


 / Published in: PHP
 

Great for generating quick reports from your drupal database in a PHP page.

Note that you will have to use the appropriate numfields and fetchfield functions for your database.

  1. <?php
  2. function show_query($sql){
  3. $rows = array();
  4. $header = array();
  5. $result = db_query($sql);
  6. while($row = db_fetch_array($result)){
  7. $rows[] = $row;
  8. }
  9. $i = 0;
  10. while ($i < mysql_num_fields($result)) {
  11. $meta = mysql_fetch_field($result, $i);
  12. $header[] = $meta->name;
  13. $i++;
  14. }
  15. print theme_table($header, $rows);
  16. }
  17. show_query("SELECT name, mail FROM {users} LIMIT 10");
  18. ?>

Report this snippet  

You need to login to post a comment.