Jump to content

[SOLVED] can't get mysql num rows


contra10

Recommended Posts

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

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>";
   }   
}   

?>

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>";
}	

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.