robertmo116 Posted January 20, 2009 Share Posted January 20, 2009 Hello! My name is Robert and I was suggested to come to PHPFreaks by one of my friends, so far I like! Well anyways, I am having a little problem.. I am runnning a case on a game i have made and I am wanting it to detect IF someone is in a gang then result in displaying the most recent 5 gang attacks - and IF not in a gang then display a group of 5 div tags with text on one of the div's saying Sorry your not in a gang. I almost found a solution for it - I got it to display the right results if not in a gang but an additional 5 div tags are for some reason running of what looks like 5 recent attacks in the game from random peeps.. this shouldnt do that as i am not in a gang. Well if this is confusing I should be online for a while longer checking out the community but if you would like to get ahold of me hit me up on aim: robertmo116 or msn: robert@mobgamingnetwork.com Thank you sooo much in advance.. I've been stuck on this problem for a few hours now and cant find a solution! :'( Well here is the Code! <?php case "1": if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } global $db,$ir,$c,$userid,$gangdata; $atks=$db->query("SELECT a.*,u1.username as attackern,u1.gang as attacker_gang, u2.username as attackedn,u2.gang as attacked_gang FROM attacklogs a LEFT JOIN users u1 ON a.attacker=u1.userid LEFT JOIN users u2 ON a.attacked=u2.userid WHERE (u1.gang={$ir['gang']} OR u2.gang={$ir['gang']}) AND result='won' ORDER BY time DESC LIMIT 5"); while($r=$db->fetch_row($atks)) { if($r['attacker_gang'] == $ir['gang']) { $color="green"; } else { $color="red"; } $d=date('F j,',$r['time']); echo "<div class='fitembgs'><a href='viewuser.php?u={$r['attacker']}'>{$r['attackern']}</a> <font color='$color'>attacked</font> <a href='viewuser.php?u={$r['attacked']}'>{$r['attackedn']}</a> on $d</div>"; } $count=mysql_num_rows($atks); if($count == 0) { echo"<div class='fitembgs'>There hasnt been any attacks</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } $update= mysql_query("UPDATE `users` SET `toolbar`='1' WHERE `userid`='$ir[userid]'"); break;?> (edited to change tags to tags) Quote Link to comment Share on other sites More sharing options...
thepip3r Posted January 20, 2009 Share Posted January 20, 2009 I'm sorry if I'm misunderstanding your problem as it's pretty cryptic but if you're not in a gang and your code is still running as if you are it seems to me that this is your problem: if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } What's the problem? ...your if statement may correctly be recognizing $ir['gang'] == 0 designating you're not in a gang (i'm assuming) but after those five divs are written via the echo, your code continues to execute all lines of code below it because it looks like the "attack" code is not in the else conditional of being in a gang or not OR you're not using exit() if you're in a gang. the exit(); method is a little terminal, final, or ungraceful (however u want to think of it) but it's one way to stop code from executing. Quote Link to comment Share on other sites More sharing options...
robertmo116 Posted January 20, 2009 Author Share Posted January 20, 2009 double post.. sorry Quote Link to comment Share on other sites More sharing options...
robertmo116 Posted January 20, 2009 Author Share Posted January 20, 2009 I'm sorry if I'm misunderstanding your problem as it's pretty cryptic but if you're not in a gang and your code is still running as if you are it seems to me that this is your problem: if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } What's the problem? ...your if statement may correctly be recognizing $ir['gang'] == 0 designating you're not in a gang (i'm assuming) but after those five divs are written via the echo, your code continues to execute all lines of code below it because it looks like the "attack" code is not in the else conditional of being in a gang or not OR you're not using exit() if you're in a gang. the exit(); method is a little terminal, final, or ungraceful (however u want to think of it) but it's one way to stop code from executing. Hmm I have tried adding the exit like the following; <?php if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } Exit(); ?> but this causes the rest of the script not to run.. its weird.. Quote Link to comment Share on other sites More sharing options...
thepip3r Posted January 20, 2009 Share Posted January 20, 2009 i don't see an exit in that code... i'm talking about something like: Well here is the Code! Code: [select] <?php case "1": if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; EXIT(); } global $db,$ir,$c,$userid,$gangdata; $atks=$db->query("SELECT a.*,u1.username as attackern,u1.gang as attacker_gang, u2.username as attackedn,u2.gang as attacked_gang FROM attacklogs a LEFT JOIN users u1 ON a.attacker=u1.userid LEFT JOIN users u2 ON a.attacked=u2.userid WHERE (u1.gang={$ir['gang']} OR u2.gang={$ir['gang']}) AND result='won' ORDER BY time DESC LIMIT 5"); while($r=$db->fetch_row($atks)) { if($r['attacker_gang'] == $ir['gang']) { $color="green"; } else { $color="red"; } $d=date('F j,',$r['time']); echo "<div class='fitembgs'><a href='viewuser.php?u={$r['attacker']}'>{$r['attackern']}</a> <font color='$color'>attacked</font> <a href='viewuser.php?u={$r['attacked']}'>{$r['attackedn']}</a> on $d</div>"; ...MORE CODE } OR Well here is the Code! Code: [select] <?php case "1": if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } ELSE { global $db,$ir,$c,$userid,$gangdata; $atks=$db->query("SELECT a.*,u1.username as attackern,u1.gang as attacker_gang, u2.username as attackedn,u2.gang as attacked_gang FROM attacklogs a LEFT JOIN users u1 ON a.attacker=u1.userid LEFT JOIN users u2 ON a.attacked=u2.userid WHERE (u1.gang={$ir['gang']} OR u2.gang={$ir['gang']}) AND result='won' ORDER BY time DESC LIMIT 5"); while($r=$db->fetch_row($atks)) { if($r['attacker_gang'] == $ir['gang']) { $color="green"; } else { $color="red"; } $d=date('F j,',$r['time']); echo "<div class='fitembgs'><a href='viewuser.php?u={$r['attacker']}'>{$r['attackern']}</a> <font color='$color'>attacked</font> <a href='viewuser.php?u={$r['attacked']}'>{$r['attackedn']}</a> on $d</div>"; ...MORE CODE } //END ELSE } Quote Link to comment Share on other sites More sharing options...
thepip3r Posted January 20, 2009 Share Posted January 20, 2009 but this causes the rest of the script not to run.. its weird.. that's the entire point of the exit(); function -- to completely halt code execution. that's why i said you should use ELSE conditional logic or some other method to only execute your "gang code" upon the appropriate conditions. Quote Link to comment Share on other sites More sharing options...
robertmo116 Posted January 20, 2009 Author Share Posted January 20, 2009 i don't see an exit in that code... i'm talking about something like: Well here is the Code! Code: [select] <?php case "1": if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; EXIT(); } global $db,$ir,$c,$userid,$gangdata; $atks=$db->query("SELECT a.*,u1.username as attackern,u1.gang as attacker_gang, u2.username as attackedn,u2.gang as attacked_gang FROM attacklogs a LEFT JOIN users u1 ON a.attacker=u1.userid LEFT JOIN users u2 ON a.attacked=u2.userid WHERE (u1.gang={$ir['gang']} OR u2.gang={$ir['gang']}) AND result='won' ORDER BY time DESC LIMIT 5"); while($r=$db->fetch_row($atks)) { if($r['attacker_gang'] == $ir['gang']) { $color="green"; } else { $color="red"; } $d=date('F j,',$r['time']); echo "<div class='fitembgs'><a href='viewuser.php?u={$r['attacker']}'>{$r['attackern']}</a> <font color='$color'>attacked</font> <a href='viewuser.php?u={$r['attacked']}'>{$r['attackedn']}</a> on $d</div>"; ...MORE CODE } OR Well here is the Code! Code: [select] <?php case "1": if ($ir['gang'] == 0) { echo "<div class='fitembgs'>Sorry your not in a gang!</div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div> <div class='fitembgs'></div>"; } ELSE { global $db,$ir,$c,$userid,$gangdata; $atks=$db->query("SELECT a.*,u1.username as attackern,u1.gang as attacker_gang, u2.username as attackedn,u2.gang as attacked_gang FROM attacklogs a LEFT JOIN users u1 ON a.attacker=u1.userid LEFT JOIN users u2 ON a.attacked=u2.userid WHERE (u1.gang={$ir['gang']} OR u2.gang={$ir['gang']}) AND result='won' ORDER BY time DESC LIMIT 5"); while($r=$db->fetch_row($atks)) { if($r['attacker_gang'] == $ir['gang']) { $color="green"; } else { $color="red"; } $d=date('F j,',$r['time']); echo "<div class='fitembgs'><a href='viewuser.php?u={$r['attacker']}'>{$r['attackern']}</a> <font color='$color'>attacked</font> <a href='viewuser.php?u={$r['attacked']}'>{$r['attackedn']}</a> on $d</div>"; ...MORE CODE } //END ELSE } THANK YOU!! Finally It Works! I appreciate it mate +1 to you!! the second option worked with a little editing 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.