Possible Duplicate:
Warning: mysql_fetch_* expects parameter 1 to be resource, boolean given error
What's the problem with this ? First 2 selects work fine, the other 2 return this error:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
<?php
$result=mysql_query("SELECT count(*) as total from urls WHERE username = '$username' AND approved = 'yes' ");
$data=mysql_fetch_assoc($result);
echo $data['total'];?></td>
<td><?php
$result2=mysql_query("SELECT count(*) as total2 from urls WHERE username = '$username' AND approved = 'no' ");
$data2=mysql_fetch_assoc($result2);
echo $data2['total2'];?></td>
<td><?php
$result3=mysql_query("SELECT count(*) as total3 from buy WHERE username = '$username' AND status = 'active' ");
$data=mysql_fetch_assoc($result3);
echo $data['total3'];?></td>
<td><?php
$result4=mysql_query("SELECT count(*) as total4 from buy WHERE username = '$username' AND status = 'complete' ");
$data=mysql_fetch_assoc($result4);
echo $data['total4'];?></td>
You can do this in one query like so:
SELECT
SUM(CASE WHEN approved = 'yes' THEN 1 ELSE 0 END) AS Total1,
SUM(CASE WHEN approved = 'no' THEN 1 ELSE 0 END) AS Total2,
SUM(CASE WHEN status = 'active' THEN 1 ELSE 0 END) AS Total3,
SUM(CASE WHEN status = 'complete' THEN 1 ELSE 0 END) AS Total4
FROM urls
WHERE username = '$username';