我的echo返回Array而不是value。
$postscount = mysql_query('select count(authorid) from topics where authorid="'.$author.'" ');
$posts = mysql_fetch_row($postscount);
这是回声:
{
echo "Posts: ".$posts." ";
}
我试过这个:
{
echo '<pre>';
print_r($posts);
echo '</pre>';
}
使用print_r它会返回:
阵列( [0] =&gt; 73)
和var_dump()
array(1){[0] =&gt; string(2)“73”}
答案 0 :(得分:0)
尝试
echo $posts[0]['count(authorid)'];
或者就像
一样echo $posts[0];
答案 1 :(得分:0)
用它来打印完整的数组:
echo '<pre>'.var_export($posts, true).'</pre>';
答案 2 :(得分:0)
试试此代码
$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";
下面
or die(mysql_error())
会告诉您查询是否成功。
答案 3 :(得分:0)
使用mysqli
$posts = $name = $mysqli->query('select count(authorid) as postcount from topics where authorid="'.$author.'" ')->fetch_object()->postcount;
echo $posts;
在PHP.net上查看更多信息http://php.net/manual/en/book.mysqli.php