I have created a simple function which takes user id and show total no. of post by the user id
function totalpost($user_id){
$sql = 'SELECT * FROM posts WHERE u_id='.$user_id;
$total = mysql_num_rows(mysql_query($sql)) or die(mysql_errno());
return $total;
}
Its working fine, but when 0 record found, it not returns anything.
I want to return 0 if there are no record found
Please help
not because you need 0, but because you have to always use
count()instead of selectiong all users posts which can be big load of data.