I'm a newbie to PHP and mySQL. I have fairly simple script, that retrieves all table names from a mySQL database.
<form method="post" action="list_records.php">
<?
// connect to database
$db = mysql_connect("host", "user", "password");
mysql_select_db("dbname",$db);
//create query
$result = mysql_list_tables ("dbname");
//create form
echo "Select table: <select name=\"mytable\">\n";
for ($i = 0; $i < mysql_num_rows($result); $i++) {
$tb_names[$i] = mysql_tablename ($result, $i);
echo "<option>$tb_names[$i]</option>\n";
}
echo "</select>";
?>
<input type="submit" value="submit">
</form>
After choosing a table, I would like to get a new drop down list with the field names, so I can generate a query: select * from $mytable where $myfield = $mycriteria
I tried with an if ($submit) (
create a new query and drop down list
)
else {
//the code above
}
but it didn't work. How do I do that?
Thanks,
Peter