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

?>

Link to comment
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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