I'm developing a PHP/MySQL application to create databases much like phpMyAdmin but just for localhost.
I have everything working except in my TABLE listings. I get the TABLE listing OK, connect to a database that I specify in a SESSION, am able to list the TABLES in a drop down, and list the field attributes in a textarea.
My problem is when I do a query of the tables, the last table's field attributes are the only ones listed so I'd like to pick a table from the drop down and show it's field attributes in the textarea. So far, I've searched for a remedy to no avail.
Here's my code for the drop down after all connections are made:
Code: Select all
echo "<form name='frm1'><p style='text-align:left;padding-left:24px;'>Available tables: ";
echo "<select name='tables'>";
$sql = "SHOW TABLES FROM $database";
$result = mysql_query($sql);
while ($row = mysql_fetch_row($result)) {
echo "<option value='{$row[0]}' selected>{$row[0]}</option>\n";
$table = $row[0];
}
echo "</select></p>\n";
echo "<p style='text-align:left;padding-left:24px;'>Table Fields:";
echo "<pre style='text-align:left;padding-left:24px;font-size:1.2em;'><textarea cols='68' rows='60' name='info'>";
$result = mysql_query("SHOW COLUMNS FROM $table");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
echo "\n</textarea></pre></form>";
Code: Select all
session_start();
$_SESSION['hostname'] = $_POST['hostname'];
$_SESSION['user'] = $_POST['user'];
$_SESSION['passwd'] = $_POST['passwd'];
$_SESSION['database'] = $_POST['database'];
$_SESSION['table'] = $_POST['table'];