Jump to content

simple comparison problem


euel

Recommended Posts

Gud pm! I need some help guys!

I made this simple code to compare $check_location to $events['location'] every loop so if they are equal it should not echo what's inside the if statement..

Here's my code:

 

  $events_set = select_all_events($mall_id, $month, $year, $public);
while($events = mysql_fetch_array($events_set))
{
$check_location = "";
	if($check_location != trim($events['event_location']))
	{
	$check_location = trim($events['event_location']);	
	echo "<tr>";
	echo "<td colspan=7 id='header'>";	
	echo "<br />";
		echo $events['event_location'];
	echo "</td>";
	echo "</tr>";

	}

 

before the loop is finished, $check_location must store a new events['location']...

I know the problem is kinda simple but the comparison can't seem to work..

Thanks in advance!

Link to comment
Share on other sites

Thanks for the reply!

you mean this --> "before the loop is finished, $check_location must store a new events['location']..." ?

i just made a typo sorry it should be --> "before the loop is finished, $check_location must store a new events['event_location']..."

 

Actually if i change  :

 

$check_location = "";

 

to a known value that $events['event_location'] have, like this :

$check_location = "Theater Area";

 

it actually works..

i think its not passing the new $check_location properly when the loop finishes ( according to me  :))..

Any ideas?

Link to comment
Share on other sites

	while($events = mysql_fetch_array($events_set))
{
$check_location = "";
	if($check_location != trim($events['event_location']))
	{

 

like Muddy says, $check_location is being set every interation, to an empty string, are you trying to test if $events['event_location'] is empty?

 

if so you could just do empty OR you could do strlen and use the output as a bool (0 = false, else = true)

 

what exactly are you trying to do, lets not focus on this broken code, lets try and figure out a way to accomplish what you want to accomplish, and I'll help you write the new code, and help you understand it..

Link to comment
Share on other sites

Thanks for the reply!!

Like Muddy Fuster said, that is what i want..

i nid to save $events['event_location'] to $check_location everytime it loops, so if it's the same content it wont repeat it.

Sorry if i didnt made it clear..

So.. how can i fix this?

 

Thanks again!

 

Link to comment
Share on other sites

I think your getting mixed up.  You are setting $check_location = ""; EVERY run through the loop, you are by doing this forcing the contents of $_check_location to be set to "" EVERY time you compare it to your database result.  This meens that it will only ever match results that are themselves empty strings.  This is not what you actualy want to happen.  Move the $check_location = ""; to the line above where your while loop starts and run the code, just to see what happens.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.