我收到 mysql_result(): Unable to jump to row 0 错误。不知道下面的函数有什么问题
function update_counter($post_id){
global $wpdb;
$query = "SELECT view_count FROM ".$wpdb->prefix."advert_views WHERE postid = $post_id";
if(@$query_run = mysql_query($query)){
$count = mysql_result($query_run, 0, 'view_count' );
$count_inc = $count + 1;
$query_update = "UPDATE ".$wpdb->prefix."advert_views SET view_count = $count_inc WHERE postid = $post_id";
if(@$query_update_run = mysql_query($query_update)){
echo 'OK';
}
}
}
好的,我用下面的代码修改了函数,错误消失了。只是参考其他问题。但我无法正确理解逻辑。任何人都可以帮助我理解实际 > 0 的逻辑吗?
function update_counter($post_id){
global $wpdb;
$query = "SELECT view_count FROM ".$wpdb->prefix."advert_views WHERE postid = $post_id";
$query_run = mysql_query($query);
if(mysql_num_rows($query_run) > 0) {
$count = mysql_result($query_run, 0, 'view_count' );
$count_inc = $count + 1;
$query_update = "UPDATE ".$wpdb->prefix."advert_views SET view_count = $count_inc WHERE postid = $post_id";
if(@$query_update_run = mysql_query($query_update)){
echo 'OK';
}
}
}