Printing database info to php table

Associate
Joined
6 Mar 2009
Posts
495
Hi Guys,

I have a database with around 16 tables within it. I have a search function that will search through each table. There are no relationships between any of the tables. Currently i am printing the database contents to a php table as follows;

Code:
echo "<table class='searchTable' border='1';  <tr>"; 
for($i = 0; $i < mysql_num_fields($result); $i++) {     
$field_info = mysql_fetch_field($result, $i);     
echo "<th>{$field_info->name}</th>"; }  

// Print the data 

while($row = mysql_fetch_row($result)) {     
echo "<tr>";     
	foreach($row as $_column) {         
		echo "<td>{$_column}</td>";     }     
		echo "</tr>"; 
		}  
		
		echo "</table>";

By doing it this way prints all the columns as there are in the database.

So what i am really trying to say is that, is there a way i can print the contents of the database to a table and be able to move the columns about. Eg. Would like to print the columns in a particular order unlike the database that they are stored in. Also by using the code above means that i can use one php page can be used instead of one page per database table. Any way i can still do this with one page??

I cant see a way but thought i would ask first.

Thanks
 
Associate
OP
Joined
6 Mar 2009
Posts
495
Thanks for the reply:)

Would i be right in saying that that code will only work if the column names are all the same throughout all tables??

For example i have around 16 tables and all have different column names and different amount of columns.
 
Back
Top Bottom