sford999 Posted February 12, 2007 Share Posted February 12, 2007 Right heres the situation. I`m creating a custom CMS for one of my sites, the admin area has various database functions such as optimize, repair etc... Now, what I`d like to do is output data from the repair, similar to how phpmyadmin does it eg: <?php $table = $_POST['table']; $sql = "OPTIMIZE TABLE $table"; $result = mysql_query($sql); var_dump(mysql_fetch_assoc($result)); ?> Will output: array 'Table' => 'some_table' (length=21) 'Op' => 'optimize' (length= 'Msg_type' => 'status' (length=6) 'Msg_text' => 'OK' (length=2) Now what I want to do, is put the results into a table, with it looping through each table and the table shows the table name, operation, msg_type and msg_text in seperate columns. Like this: But the problem is I`m clueless when it comes to this, I`ve been reading up on arrays all day long and I`m still no closer to figuring this out, thats why I`m posting here, to see if someone can help me with this. Link to comment https://forums.phpfreaks.com/topic/38206-outputting-array-into-a-loop/ Share on other sites More sharing options...
craygo Posted February 12, 2007 Share Posted February 12, 2007 Try this <?php $table = $_POST['table']; $sql = "OPTIMIZE TABLE $table"; $result = mysql_query($sql); $myarray = mysql_fetch_assoc($result); echo "<table width=800 align=center border=1>\n"; echo "<tr>\n"; foreach($myarray as $title => $result){ echo "<td>$title</td>\n"; } echo "</tr>\n"; echo "<tr>\n"; foreach($myarray as $title => $result){ echo "<td>$result</td>\n"; } echo "</tr> </table>\n"; ?> Ray Link to comment https://forums.phpfreaks.com/topic/38206-outputting-array-into-a-loop/#findComment-182957 Share on other sites More sharing options...
sford999 Posted February 13, 2007 Author Share Posted February 13, 2007 That works to a point but its showing this: Link to comment https://forums.phpfreaks.com/topic/38206-outputting-array-into-a-loop/#findComment-183188 Share on other sites More sharing options...
redarrow Posted February 13, 2007 Share Posted February 13, 2007 <?php $table = $_POST['table']; $sql = "OPTIMIZE TABLE $table"; $result = mysql_query($sql); $myarray = mysql_fetch_assoc($result); echo "<table width='800' align='center' border='1'>\n"; echo "<tr>\n"; foreach($myarray as $title => $result){ echo "<td>$title</td>\n"; } echo "</tr>\n"; echo "<tr>\n"; foreach($myarray as $title => $result){ echo "<td>$result</td>\n"; } echo "</tr> </table>\n"; ?> Link to comment https://forums.phpfreaks.com/topic/38206-outputting-array-into-a-loop/#findComment-183202 Share on other sites More sharing options...
sford999 Posted February 13, 2007 Author Share Posted February 13, 2007 Thats the same code as above, which doubles the output as in my previous post Link to comment https://forums.phpfreaks.com/topic/38206-outputting-array-into-a-loop/#findComment-183984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.