faulty IF statement
Posted: Thu Feb 05, 2004 7:48 pm
I have a very small problem in a very small block of code... so small that I can't seem to find it, and it's driving me crazy.
So you see what's happening here: we're looping through rows of SQL query. If the ItemNo returned by the row doesn't match the ItemNo we've stored in a variable, we include a file that starts a new row. Otherwise, we just echo a single line of text onto the end.
Obviously, the first time through, the ItemNo tracking variable has not yet been set, so we start a new row. Great. Next time through, we append a line of text, since the itemNo still matches. All working as it should. But, say that now on the 3rd record, we have a different ItemNo. It should be generating a new row. And yet... it's not. It continues to append strong text to the end. I've even echoed out the ItemNo variables, and they are indeed changing, yet no new rows ever get created.
This is bang-head-on-wall material here.
Code: Select all
while ($Problem_List = mysql_fetch_array($Query_Result))
{
$All_Items .= " - " . $Problem_List[ItemNo];
if($Problem_List[ItemNo] != $Current_ItemNo)
// if this is not the same item number we've been handling thus far, we need to start over with new formatting.
{
include_once 'list_item.html';
$Current_ItemNo = $Problem_List[ItemNo];
}
else
// if we've already started displaying this item, just append individual problems to it now
{
echo "<strong>$Problem_List[ProblemType]</strong>, ";
}
}Obviously, the first time through, the ItemNo tracking variable has not yet been set, so we start a new row. Great. Next time through, we append a line of text, since the itemNo still matches. All working as it should. But, say that now on the 3rd record, we have a different ItemNo. It should be generating a new row. And yet... it's not. It continues to append strong text to the end. I've even echoed out the ItemNo variables, and they are indeed changing, yet no new rows ever get created.
This is bang-head-on-wall material here.