I am trying to get my head around this issue.
$can = $r6['candidate_id'] ;
$checkquery = mysql_query("SELECT * FROM candidate
WHERE candidate_id ='$can' and type='facrep'") or die(mysql_error());
if (mysql_num_rows($checkquery) > 0) {
echo ">0" ;
}else {
echo "0" ;
}
If there is a record in the database, it succesfully returns >0
but if there are no records, it doesn't return anything, not even 0
. Consequently, the else
statement never works.
Ideas?
The mysql_num_rows returns bool false on no rows found.So you to re-write the code as
$can = $r6['candidate_id'] ;
$checkquery = mysql_query("SELECT * FROM candidate
WHERE candidate_id ='$can' and type='facrep'") or die(mysql_error());
if (mysql_num_rows($checkquery)) {
echo ">0" ;
}else {
echo "0" ;
}
this would help you out hopefully!