0

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;

<?php
$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

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by frostiecuk
0

After much searching, I've realised I hadn't closed the else statements correctly :$

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.