当我尝试从数据库中回显列计数器的值时,我收到资源ID#3错误。我想只获得一个值。任何想法我该怎么做?
$Page = $_SERVER['PHP_SELF'];
$num = preg_replace("/[^0-9]/", '', $Page);
$query = "SELECT * FROM hitscounter WHERE page='$num';";
$res = mysql_query($query);
if (mysql_num_rows($res) > 0) {
mysql_query("UPDATE hitscounter SET counter=counter+1 Where page='$num'");
$views = mysql_query("SELECT counter FROM hitscounter WHERE page=555");
mysql_fetch_array($views, MYSQL_NUM);
mysql_free_result($views);
echo $views;
}
答案 0 :(得分:1)
您应该使用result
从[{1}}返回的mysql_fetch_array
,就像这样:
$result = mysql_fetch_array($views, MYSQL_NUM);
print_r($result);
答案 1 :(得分:0)
你的if条件应该是这样的
$result = mysql_fetch_array($res);
if (count($result) > 0){
echo 'do something';
}