Simple code sample:
$query = 'SELECT COUNT(*) FROM myTable';
$exec = mysql_query($query) or die('Error: ' . mysql_error());
$numRows = mysql_result($exec, 0);
As for the SQL injection, either search the board or Google for keywords such as "prevent sql injection php".
Basically, the concept is that you don't want to pass ANY data directly into a SQL query string that could have been altered by the remote user. This includes GET/POST data, as well as some elements in the $_SERVER superglobal.
The suggestion mentioned above was to ensure that $blog_id is an integer; to do this, I would use a function such as [man]intval/man. Also, since blog_id is a numeric column in SQL, there should be no quotes around its values (e.g. "WHERE blog_id='$blogid'" shouldn't have the quotes).