home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / postgresres.php3.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  868 b   |  33 lines

  1. Postgres Result View 
  2.  
  3. This is a function to display a table for Postgres results. This this code in an include file, require it, and call ShowResults($result) whenever you need to see what your queries result in. 
  4.  
  5.  
  6. <?php 
  7.  
  8. Function ShowResults($result) { 
  9.  
  10.   if ($result) { 
  11.     $rows = pg_NumRows($result); 
  12.     $cols = pg_NumFields($result); 
  13.  
  14.     echo( "<table border=1>\n"); 
  15.      /* Create the headers */ 
  16.     echo( "<tr>\n"); 
  17.     for($i = 0; $i < $cols; $i++) { 
  18.       printf( "<th>%s</th>\n", pg_FieldName($result, $i)); 
  19.     } 
  20.     echo( "</tr>"); 
  21.     for($j = 0; $j < $rows; $j++) { 
  22.       echo( "<tr>\n"); 
  23.       for($i = 0; $i < $cols; $i++) { 
  24.         printf( "<td>%s</td>\n", pg_result($result, $j, $i)); 
  25.       } 
  26.       echo( "</tr>"); 
  27.     } 
  28.     echo( "</table>"); 
  29.   } else { 
  30.     echo(pg_errormessage); 
  31.   } 
  32. ?>