Jump to content

Outputting array into a loop


sford999

Recommended Posts

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:

phpmyadmin.jpg

 

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

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

<?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";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.