I have two MySQL queries to fetch data from a table.
Individually, the if ($query_one->num_rows() > 0)
and/or if ($query_two->num_rows() > 0)
work perfectly.
The Problem: However, when used in an elseif statement only the first query $query_one->num_rows()
fetches data. If the first query has no results, the second query $query_two->num_rows()
should trigger?
if ($query_one->num_rows() > 0)
{
return $query_one->row(0)->total;
}
else if($query_two->num_rows() > 0)
{
return $query_two->row(0)->total;
}
return 0;
I know there are posts on stackoverflow that show the correct way to implementing an elseif statement with queries, but I have already read them.
Thanks in advance
Try this way so that you would know where it goes:
if ($query_one->num_rows() > 0)
{
echo "query_one run";
return $query_one->row(0)->total;
}
else
{
if($query_two->num_rows() > 0)
{
echo "query_two run";
return $query_two->row(0)->total;
}
else
{
echo "nothing to return";
return 0;
}
}
Just remove the echo when you find out what is wrong. Maybe both the query does not return anything.