Page 1 of 1

faulty IF statement

Posted: Thu Feb 05, 2004 7:48 pm
by Unipus
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.

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>, ";
			}	
		}
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.

Posted: Thu Feb 05, 2004 9:12 pm
by penguinboy
Try it without the include.

Posted: Fri Feb 06, 2004 7:49 am
by AVATAr
change include_once for include.. or simply echo the line or html

Posted: Fri Feb 06, 2004 7:58 am
by mahara
Try with 'include()', not 'include_once()'.

Hopes help.

Posted: Fri Feb 06, 2004 1:37 pm
by Unipus
See, I KNEW it was something head-slappingly dumb I had done. That's when you know it's time to go home for the night.