Getting the number of posts a user has by the number of rows returned?
- by transparent
So I have a question.
I have chatting/IM website that I am working on and I was making a user profile page. I wanted to show how many posts that user had.
Another issue I had earlier was that when I called a certain value it would return a 'Resource #1' type string. But I got that working by using
$totalposts=mysql_query("SELECT * FROM `posts` WHERE Username='" . $username . "'");
$totalposts = mysql_fetch_row($totalposts);
$totalposts = $totalposts[0];
But that just returns the last postID of the most recent post. I thought that mysql_num_rows would work. But this code returns an error (example with numbers):
29: $totalposts=mysql_query("SELECT * FROM `posts` WHERE Username='" . $username . "'");
30: $totalposts = mysql_num_rows($totalposts);
31: $totalposts =mysql_fetch_row($totalposts);
32: $totalposts = $totalposts[0];
That returns this error:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/a9091503/public_html/im/user.php on line 31
Thanks guys. :) I hope you can figure this out. :D