My echo returns Array instead of value.
$postscount = mysql_query('select count(authorid) from topics where authorid="'.$author.'" ');
$posts = mysql_fetch_row($postscount);
Here's echo:
{
echo "Posts: ".$posts." ";
}
I tried with this:
{
echo '<pre>';
print_r($posts);
echo '</pre>';
}
with print_r it retuns this:
Array ( [0] => 73 )
and with var_dump()
array(1) { [0]=> string(2) "73" }
Try this code
$postscount = mysql_query('select count(authorid) from topics where authorid="'.$author.'" ') or die(mysql_error());
$posts = mysql_fetch_row($postscount);
var_dump($posts);
echo "There are ".$posts[0]. " authors";
Here
or die(mysql_error())
will tell you that query was successful or not.
Try with
echo $posts[0]['count(authorid)'];
Or just like
echo $posts[0];
Use this to print your complete array :
echo '<pre>'.var_export($posts, true).'</pre>';
Use mysqli
$posts = $name = $mysqli->query('select count(authorid) as postcount from topics where authorid="'.$author.'" ')->fetch_object()->postcount;
echo $posts;
See more on PHP.net http://php.net/manual/en/book.mysqli.php