Reputation: 3
I wanted the page to show a value
Im having a problem in coding it
<?php
$result = mysql_query("SELECT COUNT(*) as refcount FROM users where reffered = ".$row['username']."");
if($result === FALSE) {
die(mysql_error());
}
while($row=mysql_fetch_array($result))
{
echo $row['refcount'];
}
?>
sample table:
username | reffered
ace you
bin ace
cat ace
qqqq ace
it should show the value 3 on the php
since ace referred 3 bin , cat and qqqq
Error in this line
Unknown column 'qqqq' in 'where clause'
qqqq is username
Upvotes: 0
Views: 200
Reputation: 23510
You can use alias to count and then to print it as follow
$result = mysql_query("SELECT COUNT(*) as refcount FROM referred where ref_id = 'user_id'");
while($row=mysql_fetch_array($result))
{
echo $row['refcount'];
}
Upvotes: 1