警告:mysql_result():无法跳转到MySQL结果索引的第0行

时间:2012-10-10 11:03:34

标签: php mysql row

  

可能重复:
  MySQL- Unable to jump to row 0 on MySQL result index

我收到mysql_result():无法跳转到第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';
        }
    }
}

0 个答案:

没有答案