If you want to print all tables using values in mysql , you can use the following code:
<?php mysql_connect ("localhost", "DB_USER", "DB_PASSWORD"); //your mysql connection mysql_select_db('DB_NAME') or die( "Unable to select database"); //your db name $tables = mysql_query("SELECT table_name FROM information_schema.tables WHERE table_schema='DB_NAME'"); //pull tables from theh databsase while ($table= mysql_fetch_row($tables)) { $rsFields = mysql_query("SHOW COLUMNS FROM ".$table[0]); while ($field = mysql_fetch_assoc($rsFields)) { echo $table[0].".".$field["Field"].", "; //prints out all columns } echo $table[0]; $query = "SELECT * FROM ".$table[0]; //prints out tables name $result = mysql_query($query); PullValues($result); //call function to get all values } //function to pull all values from tables function PullValues($result) { if($result == 0) { echo "<b>Error ".mysql_errno().": ".mysql_error()."</b>"; } elseif (@mysql_num_rows($result) == 0) { echo("<b>Query completed. No results returned.</b><br>"); } else { echo "<table border='1'> <thead> <tr><th>[Num]</th>"; for($i = 0;$i < mysql_num_fields($result);$i++) { echo "<th>" . $i . " - " . mysql_field_name($result, $i) . "</th>"; } echo " </tr> </thead> <tbody>"; for ($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr><td>[$i]</td>"; $row = mysql_fetch_row($result); for($j = 0;$j < mysql_num_fields($result);$j++) { echo("<td>" . $row[$j] . "</td>"); } echo "</tr>"; } echo "</tbody> </table>"; } //end else } ?>
I use this and work fine in mysql , for mysqli you need to tweak it a bit.
Hope this helps.
source share