Click to See Complete Forum and Search --> : 2nd Select Box not populating


coolboarderguy
05-12-2005, 01:43 AM
Hi All,

the below code only populates the 1st select box. I'm new to PHP etc. Do I have to connect to the db again, in the second block of code..? Should the variables in the 2nd block of code, be named differently to the 1st block.? In ASP the query variables would be named uniquely, identifying each query like so, prod_query_num, prod_query_result and so forth. I must admit, my recollection of ASP is very vague. Anything I've missed/not understood.?

<html>
<body>
<hr>
<h1 align=center>JUMBO STATUS</h1><p>
<center>Used Hardware Specialist</center>
<hr>
<h2 align=center>Admin</h2>
<table align="center" border="2">
<tr>
<td><h3 align=center>PRODUCT TYPE</h3></td>
</tr>
<tr><td><center>
<select name="slct_poduct_type">
<?php
$db = mysql_connect("localhost", "root", "grunger");
mysql_select_db("status",$db);
$result = mysql_query("SELECT ProductTypes.product_type_detail, ProductTypes.product_type_id FROM ProductTypes",$db);
$num = mysql_num_rows($result);
for ($i=0; $i<$num; $i++){
$myrow=mysql_fetch_array($result);
$product_type=mysql_result($result,$i,"product_type_detail");
$product_type_id=mysql_result($result,$i,"product_type_id");
$maker=mysql_result($result,$i,"maker_detail");
$maker_id=mysql_result($result,$i,"maker_id");
echo "<option value=\"$product_type_id\">$product_type</option><br>";
}
?>
</select>
</center>
</td></tr>
</table>
<table align="center" border="2">
<tr>
<td><h3 align=center>Maker</h3></td>
</tr>
<tr><td><center>
<select name="slct_maker">
<?php
$maker_db = mysql_connect("localhost", "root", "grunger");
mysql_select_db("status",$maker_db);
$maker_result = mysql_query("SELECT Makers.maker_id Makers.maker_detail FROM Makers",$maker_db);
$maker_num = mysql_num_rows($maker_result);
for ($i=0; $i<$maker_num; $i++){
$maker_myrow=mysql_fetch_array($maker_result);
$maker=mysql_result($maker_result,$i,"maker_detail");
$maker_id=mysql_result($maker_result,$i,"maker_id");
echo "<option value=\"$maker_id\">$maker</option><br>";
}
?>
</select>
</center>
</td></tr>
</table>
<p>
<p>
<p>
<hr><center>email: status1@zae.att.ne.jp<p>
Telephone: 03-5209-1777<p>
Fax: 03-5209-2539
</center>
<hr>
</body>
</html>

NogDog
05-12-2005, 09:55 AM
Since both queries are to the same database, you only need to mysql_connect and mysql_select_db once. I don't know if that would have anything to do with your second one not populating, though. If not, then you need to test the query result to see if it's failing (improperly formatted) or returning nothing (proper query syntax but logically wrong):

$result = mysql_query($query_string);
if($result == FALSE)
{
die("Query 2 failed with MySQL error ".mysql_errno().": ".mysql_error());
}
elseif(mysql_num_rows($result) == 0)
{
die("Query 2 returned 0 rows.");
}
# query worked, so go ahead and use it...

This at least should point to where to look to figure out what the problem is.