> where can I find a simple php to generate a default html table
> from a MySql table ? 

Try this (but specify your own username, password, database name, and query string 
in the first three lines):

<?php 
 $sock = mysql_connect("localhost", "username", "password");
 mysql_select_db("database",$sock);
 $query = "select * from table1"; 

 $res = mysql_query($query,$sock);
 if (!$res)
   { echo("ERROR: ".mysql_error($sock)." ".__FILE__); exit; }
 $row = mysql_fetch_row($res);
 if (strlen($row) == 0)
   { echo("NO DATA found matching request"); exit; }

 echo("<table><tr>");
 $numcols = mysql_num_fields($res);
 // output field names for column headings:
 for ($i=0; $i < $numcols; $i++) 
   { echo("<th>".mysql_field_name($res, $i)); }

 while (strlen($row))
   {
     echo("<tr>");
     for ($i=0; $i < $numcols; $i++) 
       { echo("<td>".$row[$i]); } // output data
     $row = mysql_fetch_row($res);
   }
  echo("</table>");
}
?>


> Hello,
> where can I find a simple php to generate a default html table from a MySql
> table ?
> 
> thanks
> 
> Luigi
> 



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to