Having a stupid moment...
Posted: Sat Oct 06, 2007 1:42 am
I can't debug this, for some reason... Almost certainly PEBKAC 
I'm have PHP code to query a MySQL database and display a list of items (groceries actually) and am now working on the update to the database (so when the list is edited, the changes are saved). As part of this (a debugging step) I'm trying to echo the variables that I'll be writing in a loop. Unfortunately, the first time through the loop it works, subsequent passes are returning blanks.
Here's the code.
The first loop (where $i=0) it returns the name of the item, amount, selected status, and asile number. The rest of the iterations, it returns blanks.
Could one of the gurus on this forum look it over and help me have one of those "head-slap" moments? I've looked at this so many times my eyes are getting blurry, but I'm just not seeing whatever stupid mistake I made
TIA
I'm have PHP code to query a MySQL database and display a list of items (groceries actually) and am now working on the update to the database (so when the list is edited, the changes are saved). As part of this (a debugging step) I'm trying to echo the variables that I'll be writing in a loop. Unfortunately, the first time through the loop it works, subsequent passes are returning blanks.
Here's the code.
Code: Select all
$asiles_query="SELECT * FROM asiles ORDER BY 'number'";
$asiles_result=mysql_query($asiles_query);
$asiles_num=mysql_numrows($asiles_result);
$item_query="SELECT * FROM items";
$item_result=mysql_query($item_query);
$item_num=mysql_numrows($item_result);
// This is the outer display loop
echo "<table>\n";
echo "<tr>\n<td> </td>\n<td>Item</td>\n<td>Amount</td>\n<td>Asile</td>\n<td> </td>\n</tr>";
$i=0;
while ($i < $item_num)
{
$name=mysql_result($item_result,$i,"name");
$amount=mysql_result($item_result,$i,"amount");
$asile=(mysql_result($item_result,$i,"asile")-1);
$selected=mysql_result($item_result,$i,"selected");
echo "<tr>\n";
echo "<form method=\"POST\" action=\"make_list.php\" >\n<td>";
echo "<INPUT TYPE=CHECKBOX ";
if ($selected=="yes")
{
echo "CHECKED";
}
echo " name=\"checkbox_item[$i]\">\n</td>\n";
echo "<td>\n<INPUT TYPE=text VALUE=\"".$name."\" name=\"name_item[$i]\">\n</td>\n";
echo "<td>\n<INPUT TYPE=text VALUE=\"".$amount."\" name=\"amount_item[$i]\">\n</input>\n</td>\n";
echo "<td>\n<SELECT NAME=\"asile_item[$i]\">\n";
// This is the loop to set the asile dropdown
$a=0;
while ($a < $asiles_num)
{
if ($a==mysql_result($item_result,$i,"asile"))
{
echo "<OPTION VALUE=\"".$a. "\" selected> ".mysql_result($asiles_result,$a,"name")."</option>\n";
}
else
{
echo "<OPTION VALUE=\"".$a."\"> ".mysql_result($asiles_result,$a,"name")."</option>\n";
}
$a++;
}
echo "</SELECT>\n";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">\n</form>\n</td>\n</tr>\n";
$i++;
}
echo "</table>";
echo "\n\n";
//here's the broken part //
for($i=0;$i<$item_num;$i++){
echo "name=$name_item[$i], amount=$amount_item[$i], selected=$checkbox_item[$i], asile=$asile_item[$i] <br>";
}
?>Could one of the gurus on this forum look it over and help me have one of those "head-slap" moments? I've looked at this so many times my eyes are getting blurry, but I'm just not seeing whatever stupid mistake I made
TIA