Bradley99 Posted June 28, 2012 Share Posted June 28, 2012 Sup guys, I have some if elseif code to determine what should be shown if x = y (DUH). The if elseif part works fine. I.e if x=y then it echo's what it should, and if x=z it echo's what it should. But it ALSO displays what's underneath the if elseif. Here's the code: <? $pickdone = mysql_query("SELECT * FROM fights WHERE event='$viewevent' AND id NOT IN (SELECT fight_id FROM betting WHERE user_id='$user->id')"); $nofights = mysql_query("SELECT * FROM fights WHERE event='$viewevent'"); if ( mysql_num_rows( $nofights ) == 0 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>There are currently no scheduled fights for this event, please check back soon.</b></font></td></tr></table> <BR>"; elseif ( mysql_num_rows( $pickdone ) == 0 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>You have completed your picks for this event, please check back after '$fetch->date' to see your score.</b></font></td></tr></table> <BR>"; else ?> I tried adding an exit(); before the last else, but that doesn't work. Any help is appreciated. (Oh and i know I'm terrible at explaining my problems HA) Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/ Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 So, If either of the 2 if elseif's are true, then the rest of the page should die. Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357705 Share on other sites More sharing options...
redarrow Posted June 28, 2012 Share Posted June 28, 2012 Your trying to check two different condition's, so the if statement only needed but twice. <?php $pickdone = mysql_query("SELECT * FROM fights WHERE event='$viewevent' AND id NOT IN (SELECT fight_id FROM betting WHERE user_id='$user->id')"); $nofights = mysql_query("SELECT * FROM fights WHERE event='$viewevent'"); if ( mysql_num_rows( $nofights ) == 0 ){ echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>There are currently no scheduled fights for this event, please check back soon.</b></font></td></tr></table> <BR>"; } if ( mysql_num_rows( $pickdone ) == 0 ){ echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>You have completed your picks for this event, please check back after '$fetch->date' to see your score.</b></font></td></tr></table> <BR>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357714 Share on other sites More sharing options...
memfiss Posted June 28, 2012 Share Posted June 28, 2012 $first = mysql_num_rows( $nofights ) == 0; $second = mysql_num_rows( $pickdone ) == 0; if ( $first ) ... elseif ( $second ) ... if ($first && $second ) exit(0); Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357715 Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 It can only be one or the other, not first && second. So if it's first that is true, i need to exit after the first echo is that's possible. Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357719 Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 I told you i was crap at explaining. If the first is true, the first echo should show, then exit. If the second if true, the second echo should show, then exit. If neither is true, the code displayed BELOW that PHP should show. But what's happening is, it's show BOTH the Echo & the code displayed below. Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357721 Share on other sites More sharing options...
redarrow Posted June 28, 2012 Share Posted June 28, 2012 that because there both set as 0, set one as 1 add a entry to one of them your see! Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357723 Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 Alright, I changed the code, and the if query works, but again it displays the code below when the query is true, so it displays the echo AND the code below. Full Code: <? $viewevent=$_GET['viewevent']; $bonusdone = mysql_query("SELECT * FROM betting WHERE user_id='$user->id' AND fight_id='0'"); if ( mysql_num_rows( $bonusdone ) == 1 ) echo "<table class='thinline' cellpadding='0' cellspacing='0' width='85%'> <tr> <td class='Tableheading'><font color='#ff8a00'><b>You have completed your Bonus Award picks for this event, please check back after '$fetch->date' to see your score.</b></font></td> </tr><tr><td class='subtableheader'>Make sure you've completed all your fight picks above</td></tr></table> <BR>"; else ?> <? if ($_POST['Submit1']){ $fotn_id = $_POST['fotn_id']; $sotn_id = $_POST['sotn_id']; $kootn_id = $_POST['kootn_id']; { mysql_query("INSERT INTO betting (`bet_id` , `event_id` , `fight_id` , `user_id` , `fighter_id`, `method`, `round`, `bonus`, `fotn_id`, `sotn_id`, `kootn_id`) VALUES ('', '$fetch->id', '0', '$user->id', '0', '0', '0', '0', '$fotn_id', '$sotn_id', '$kootn_id' )") or die (mysql_error()); $url = '?viewevent=$viewevent'; echo "Your bonus pick is in, Good Luck <META HTTP-EQUIV=Refresh CONTENT='1'; URL='.$url.'>"; }} ?> <table class="main" align"left" style='table-layout:fixed' cellpadding="2" cellspacing="0" rules="none" width="100%"> <col width=40> <col width=20> <col width=20> <col width=20> <tbody> <tr> <td colspan="4" align="left" class="TableHeading"> <b><?php echo "$viewevent"; ?> Bonus Picks</b></td> </tr> <tr> <td class="subtableheader" width="40%">Fight of the Night:</td> <td class="subtableheader" width="20%">KO of the Night:</td> <td class="subtableheader" width="20%">Submission of the Night:</td> <td class="subtableheader" width="20%">Finished:</td> </tr> <form action='' method='post'><tr> <td class="profilerow" ><select name="fotn_id"> <?php $select_fotn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_fotn)){ echo "<option value=\"" .$the->id . "\">" .$the->fighter1 . _vs_ .$the->fighter2 . "</option>\r"; } ?> </select></td> <td class="profilerow"><select name="kootn_id"> <?php $select_sotn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_sotn)){ echo "<option value=\"" .$the->fighter1 . "\">" .$the->fighter1 . "</option>\r <option value=\"" .$the->fighter2 . "\">" .$the->fighter2 . "</option>\r"; } ?> </select></td> <td class="profilerow" ><select name="sotn_id"> <?php $select_kootn = mysql_query("SELECT id, fighter1, fighter2 FROM fights WHERE event='$viewevent' ORDER by id ASC"); while($the=mysql_fetch_object($select_kootn)){ echo "<option value=\"" .$the->fighter1 . "\">" .$the->fighter1 . "</option>\r <option value=\"" .$the->fighter2 . "\">" .$the->fighter2 . "</option>\r"; } ?> </select></td> <input type='hidden' name='fight_id' value='$the->id'> <td class='profilerow'><input type='Submit' name='Submit1' value='Pick' class='Submit' /> </td></form> </tr></tbody></table> </center> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357725 Share on other sites More sharing options...
Bradley99 Posted June 28, 2012 Author Share Posted June 28, 2012 Sorted it, Just added $viewevent=$_GET['viewevent']; $bonusdone = mysql_query("SELECT * FROM betting WHERE user_id='$user->id' AND fight_id='0'"); if ( mysql_num_rows( $bonusdone ) == 1 ) exit(); Right before the html code. Quote Link to comment https://forums.phpfreaks.com/topic/264942-exit-before-last-else/#findComment-1357735 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.