faulty IF statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

faulty IF statement

Post 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.
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

Post by penguinboy »

Try it without the include.
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

change include_once for include.. or simply echo the line or html
mahara
Forum Commoner
Posts: 37
Joined: Wed Nov 13, 2002 1:08 am
Location: Bandung, Jawa Barat, Indonesia

Post by mahara »

Try with 'include()', not 'include_once()'.

Hopes help.
Unipus
Forum Contributor
Posts: 409
Joined: Tue Aug 26, 2003 2:06 pm
Location: Los Angeles, CA

Post 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.
Post Reply