Re: the subject title, I'm not really sure what the problem would be called. :o
But if anyone can help me out that'd be great...
I'm trying to display a graphic if a query result equals '0' and a different graphic if it's not equal to '0'. I reckon it's probably to do with the "if" part of my code, but not too sure.
These graphics and numbers are displayed within results of another query.
for example - my results could be...
John: 13, 6, 0, 3
Bob: 45, 67, 1, 7
Dave: 54, 6, 2, 7
with john, bob, dave being the results from a search query.
The problem is that it displays the same graphic whether it's a '0' or not (example John 0, Bob 1, Dave 2 display the same graphic). Everything else seems to be working ok. In my database, each row has a couple of columns with either a 1 or 0 (which I set as an integer) I'm adding up all the 1's and 0's and displaying those results as the numbers - which works no problem, but then I want the graphic (with a link) underneath the displayed number to appear as a different graphic (with no link) if the result is a '0'
Hope that makes sense - I'm a total newbie, so struggling a fair bit trying to teach myself php. I'm sure it's problably something real simple...
$other_q = "SELECT COUNT(`set`.`other`) AS n,
SUM(`set`.`other`) AS sum
FROM `set` NATURAL JOIN `user`
WHERE `user`.`name` like '$curr_name'";
$other_result = $connection->query($other_q);
if (DB::isError($other_result)){
die("Could not query the database:<br />".
$other_q." ".DB::errorMessage($other_result));
}while ($other_am = $other_result->fetchRow())
echo "<td>{$other_am[1]}</td>";
//NOTE: everything up to here works no problem, but included the above just in case
if ($other_am[1] == 0) {
$other_code = "<td><img src='1.jpg' /></td>";
} else {
$other_code = "<td><a href='test.php'><img src='2.jpg' /></a></td>";
}
//heap of code removed here
echo $other_code;
currently...
"== 0" uses the first line of code (displaying 1.jpg) even if the number displayed over the 3 results are 1, 0, 2
"== 1" (or any other number) uses the 'else' code (2.jpg) with the same pic displayed number for three results (1, 0, 2) - even if I change it to "== 3" is still displays this pic.
any help at all would be much appreciated.
thanks.