contra10 Posted February 18, 2009 Share Posted February 18, 2009 i'm trying to create an if statement in which if the row doens't exists a statement is shown but the statement does not show as i know there should be no result <?php $querye = "SELECT * FROM `events` WHERE `evcategory`='cultural' and val='true' and `evcity`='$city' and `country` = '$country' ORDER BY dateofevsearch ASC"; $resulte = mysql_query($querye) or die(mysql_error()); $checkifex = mysql_num_rows($resulte); while ($postede = mysql_fetch_assoc($resulte)) { $eventname = "{$postede['evname']}"; $eventid = "{$postede['eid']}"; $eventsubcat = "{$postede['evsubcategory']}"; if ($checkifex != 0) { echo"<table align= 'left'>"; echo "<tr><td align='center'>$eventname $checkifex<br>"; echo"</td></tr>"; echo"</table>"; }else{ echo"<table>"; echo "<tr><td>There are no results at this time</td></tr>"; echo "</table>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/ Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 You said if a row doesn't exist..sooo...? You can do an IF on this.. if($checkifex == 0) { //do something } Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/#findComment-764754 Share on other sites More sharing options...
contra10 Posted February 18, 2009 Author Share Posted February 18, 2009 but if i say that it doesn't exist then it will echo nothing as 0 retrieves no result...if it is not equal to 0 then i have results in my query hence it echos...my problem is that the "There are no results at this time" never shows Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/#findComment-764756 Share on other sites More sharing options...
allworknoplay Posted February 18, 2009 Share Posted February 18, 2009 That's because you don't have any statements for it!! Use this... <?php $querye = "SELECT * FROM `events` WHERE `evcategory`='cultural' and val='true' and `evcity`='$city' and `country` = '$country' ORDER BY dateofevsearch ASC"; $resulte = mysql_query($querye) or die(mysql_error()); $checkifex = mysql_num_rows($resulte); while ($postede = mysql_fetch_assoc($resulte)) { $eventname = "{$postede['evname']}"; $eventid = "{$postede['eid']}"; $eventsubcat = "{$postede['evsubcategory']}"; if ($checkifex != 0) { echo"<table align= 'left'>"; echo "<tr><td align='center'>$eventname $checkifex<br>"; echo"</td></tr>"; echo"</table>"; }elseif($checkifex == 0){ echo"<table>"; echo "<tr><td>There are no results at this time</td></tr>"; echo "</table>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/#findComment-764758 Share on other sites More sharing options...
trq Posted February 18, 2009 Share Posted February 18, 2009 You need to do the check outside of your while(), otherwise that should throw an error. <?php $querye = "SELECT * FROM `events` WHERE `evcategory`='cultural' and val='true' and `evcity`='$city' and `country` = '$country' ORDER BY dateofevsearch ASC"; $resulte = mysql_query($querye) or die(mysql_error()); if ($checkifex = mysql_num_rows($resulte)) { while ($postede = mysql_fetch_assoc($resulte)) { $eventname = $postede['evname']; $eventid = $postede['eid']; $eventsubcat = $postede['evsubcategory']; echo"<table align= 'left'>"; echo "<tr><td align='center'>$eventname $checkifex<br>"; echo"</td></tr>"; echo"</table>"; } } else { echo"<table>"; echo "<tr><td>There are no results at this time</td></tr>"; echo "</table>"; } ?> Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/#findComment-764760 Share on other sites More sharing options...
contra10 Posted February 18, 2009 Author Share Posted February 18, 2009 ohhh...ok thxs Link to comment https://forums.phpfreaks.com/topic/145670-solved-cant-get-mysql-num-rows/#findComment-764762 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.