I’m stumped on this. I have a query that gets 1 column from a table, then the script counts how many id’s are in that field and then displays, and while it works, it does’t seem to compensate for empty values. code is below
[php]
<?php
// Require config.php to connect to venzo MySQL server, and other functions
require_once 'config.php';
require_once 'functions.php';
$qry = mysql_query("SELECT id, fullname, label, email, country_code FROM clients c WHERE c.in_aff = 1");
?>
Reward Members
Client ID |
Client Name |
Label |
<td>Email</td>
<td>Country</td>
<td>No. of <br /> Referred Clients</td>
<td>Total Rewards <br /> Sales (To Date)</td>
</tr>
<?php while($r = mysql_fetch_array($qry)) {
$q = mysql_query("SELECT reward_id FROM rewards WHERE user_id = $r[id]");
$row = mysql_fetch_assoc($q);
for($i = 0; $i < count($row); $i++) {
$tmp = explode(",", $row['reward_id']);
}
?>
<tr>
<td><?=$r['id']?></td>
<td><?=$r['fullname']?></td>
<td><?=$r['label']?></td>
<td><?=$r['email']?></td>
<td><?=$r['country_code']?></td>
<td><?=count($tmp)?></td>
<td></td>
</tr>
<?php } ?>
[/php]
What's happening is this
[code]
7 Kevin Tunes email US 3
79 Aleasha one email US 1
[/code]
print_r($tmp) output
[code]
Array ( [0] => 62 [1] => 394 [2] => 79 )
Array ( [0] => )[/code]
That 1 is supposed to be 0 since she doesn’t have an entry in the rewards table. For whatever reason, instead of count($tmp) returning 0, it detects the space in [ 0 ] => (spaces are intentional) as a value and displays a 1 on the screen.
I’ve tried detecting the space, but i can’t get anything to change the 1 to a 0.
Anyone have any ideas? i have to get this fixed asap.