Thanks Peter...that was extremely helpful. I think I almost have it now but just can't figure out what to put for the "WHERE" in the last SELECT statement. Can you put a second set of eyes on it for me? It's in the //TABLE BROWSER section and I have it makrked with "NOT SURE WHAT TO PUT HERE".
Thanks so much.
Here's the actual web page:
http://www.gamehermit.com/mysqltest2.php
Here's my code so far:
<?php
mysql_connect("localhost", "user_name", "password") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
$thispage = $_SERVER['PHP_SELF'];
mysql_select_db( $db );
// POPULATE DROPDOWN CONTROL FOR USER'S CHOICE OF TABLE IN CHOSEN DB:
$query="SELECT * FROM Races";
$res = mysql_query($query);
// $res = mysql_query( "SHOW tables" ) or exit( mysql_error() );
// echo " <b>Race:</b> \n",
// " <select name='racechoice' onChange='table_submit(this.form)'>\n";
echo "\n<FORM name='RaceForm' id='prompt' action='$thispage' method='GET'>\n",
" <b>Race:</b> \n <select name='db' onChange='db_submit(this.form)'>\n";
while( $row = mysql_fetch_row( $res )) {
// $sel = ( $table === $row[0] ) ? "id='sel' selected" : "";
$sel = ( $row[0] ) ? "id='sel' selected" : "";
printf( " <option %s value='%s'>%s</option>n", $sel, $row[0], $row[0] );
}
echo " </select>\n",
" <input id='edit' type='button' value='Choose a Race' onClick='db_submit(this.form)'>\n";
// BROWSE THE TABLE
if( !isset( $row )) echo "<br>Nothing to browse.";
else
{
$res = mysql_query( "SELECT * FROM `Races` NOT SURE WHAT TO PUT HERE" ) or exit( mysql_error() );
echo "<br/>Found ", mysql_num_rows( $res ), " rows in $db:<br/>";
r2html( $res );
}
echo "</body>\n</html>";
// TABLE BROWSER
function r2html( $res, $tblformat="border='1'" ) { // PAINT RESULT AS HTML TABLE
echo "<table $tblformat>\n<tr>";
for( $i = 0; $i < mysql_num_fields( $res ); $i++ )
echo "<td><b>", mysql_field_name( $res, $i), "</b></td>\n";
echo "</tr>\n";
while( $row = mysql_fetch_row( $res )) {
echo "<tr>";
foreach( $row as $c ) echo "<td>",(empty($c) ? ' ' : $c),"</td>";
echo "</tr>\n";
}
echo "</table>\n";
}
echo "</body>\n</html>";
?>