Hi All

I'm new here and have searched high and low for an answer to my problem, and have so far had no joy.

I am trying to create a if/else statement depending on the outcome of a SQL command that should be extremely simple and basic, but for some reason, I dont see the results I expect.

The code I have is as follows;

$compcode = $company['id'];
$q = mysql_query("SELECT COUNT(id) AS whattotal FROM tbl_discounts WHERE company_id = $compcode");
while($r = mysql_fetch_array($q)){
echo "Number found: ".$r['whattotal'].". Company ID:".$compcode; };
if($r['whattotal']==0){ echo "Less";}
else { echo "More"; } ?>

When the page loads, the if/else condition always returns "LESS". I added the echo statements to see what is being returned and can confirm that $r is performing correctly. Even when this returns 12, the output is still LESS when I would expect it to be "MORE".

I'm sure there is a simple explanation, but im struggling to find it. Any advice?

Many thanks