euel Posted January 16, 2012 Share Posted January 16, 2012 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! Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 16, 2012 Share Posted January 16, 2012 what is the value of $check_location and what are the potential values of $events['location'] I already see 1 issue, you named $events['location'] "$events['event_location']" in your code, that could be your problem:P Quote Link to comment Share on other sites More sharing options...
euel Posted January 16, 2012 Author Share Posted January 16, 2012 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? Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 16, 2012 Share Posted January 16, 2012 you are resetting $check_location every itteration. It's likely never going to match your database string. Unless this is what you want you should move the line "$check_location = "";" outside the while loop, just above it. Quote Link to comment Share on other sites More sharing options...
RussellReal Posted January 16, 2012 Share Posted January 16, 2012 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.. Quote Link to comment Share on other sites More sharing options...
euel Posted January 16, 2012 Author Share Posted January 16, 2012 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! Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted January 16, 2012 Share Posted January 16, 2012 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. Quote Link to comment Share on other sites More sharing options...
euel Posted January 17, 2012 Author Share Posted January 17, 2012 eeeee... your right! im sooo mixed up.. didn't realize it was inside my loop... sorry for bothering you guys, 2hrs of sleep <---- i blame you!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.