0

I'm not sure why this is not working:

if($strFilterByStatus != 'all' &&  $strFilterByYear == 'all' && $strFilterByMonth !='all')
{
    $strSQL = "SELECT * FROM tblcase where recovered = '".$strFilterByStatus."' and monthreported = '".$strFilterByMonth."'" ;
}
else if($strFilterByStatus != 'all' &&  $strFilterByYear != 'all' && $strFilterByMonth !='all')
{
    $strSQL = "SELECT * FROM tblcase where recovered = '".$strFilterByStatus."' and yearreported = '".$strFilterByYear."' and monthreported = '".$strFilterByMonth."'" ;
}


if (mysql_num_rows($strSQL)==0)
{
    $strCaseExist = false;
}
else
{
    $SQL=mysql_query($strSQL);  
    $strCaseExist = true;
}

I have 2 different SQL statements and I just want to know if it will return a record or not.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
Birdun
  • 7
  • 4
  • Please [don't use `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php?rq=1); the `mysql_*` functions are outdated, [deprecated](http://us3.php.net/manual/en/intro.mysql.php), and insecure. Use [`MySQLi`](http://us3.php.net/manual/en/book.mysqli.php) or [`PDO`](http://us3.php.net/manual/en/intro.pdo.php) instead. – elixenide Mar 08 '14 at 16:30
  • 3
    Because you're not executing the query, simply setting a string containing the query – Mark Baker Mar 08 '14 at 16:31
  • ah yeah mark baker your right dammmmmmn so stupid not to see that thank you @ed cottrell thanks i will take it to consideration – Birdun Mar 08 '14 at 16:33

3 Answers3

2

You are not executing the query.check this manual for more details on mysql_num_rows() ,change your code like this

$resrce =mysql_query($strSQL)
if (mysql_num_rows($resrce)==0)

Beware about mysql functions, they are insecure and deprecated. Choose mysqli or pdo

Sanoob
  • 2,466
  • 4
  • 30
  • 38
2

mysql_num_rows requires a resultset to be passed not a string variable. Change to the following code:

$result = mysql_query( $strSQL );
$strCaseExist = (mysql_num_rows($result) == 0) ? false : true;
hjpotter92
  • 78,589
  • 36
  • 144
  • 183
1

you have to execute the query BEFORE checking for num rows.

JohnKochJR
  • 133
  • 1
  • 10