mysql对象没有转换为int

时间:2016-01-28 09:43:48

标签: php mysql

所以,我有一个wp mysql db列如下:

`update_number` =  int(11) Null:No, default:0

然后我有以下php:

$RSS_UPDATE = $wpdb->get_results("SELECT update_number FROM $table WHERE sub_id = $post_id");
if ( $RSS_UPDATE )
{
    foreach ( $RSS_UPDATE as $RSS_SINGLE )
    {
        $RSS_ROW_NEW  = $RSS_SINGLE + 1;            
        $wpdb->update($table, array('update_number' => $RSS_ROW_NEW),array( 'sub_id' => $post_id ));    
    }   
}

所以我的想法是,对于sub_id = $post_id的任何结果,然后获取所有update_number。 (即可能是“0,2,1,4,2,2”)

然后,对于每个值,我想将整数值增加+1并更新它。

但是,我得到Object of class stdClass could not be converted to int

我做错了什么?

1 个答案:

答案 0 :(得分:0)

我认为你需要确保$ RSS_SINGLE是字符串或int

的var_dump($ RSS_SINGLE);出口;



$RSS_UPDATE = $wpdb->get_results("SELECT update_number FROM $table WHERE sub_id = $post_id");
if ( $RSS_UPDATE )
{
    foreach ( $RSS_UPDATE as $RSS_SINGLE )
    {
        $RSS_ROW_NEW  = $RSS_SINGLE->update_number + 1;            
        $wpdb->update($table, array('update_number' => $RSS_ROW_NEW),array( 'sub_id' => $post_id ));    
    }   
}