douzong7283 2014-05-26 16:55
浏览 65
已采纳

$ wpdb-> get_results无效

i write following code to copy values from one table to another table but $wpdb->get_results not returning anything.

function rating_convert() {
    global $wpdb;
    $likes = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'up_down_comment_vote_totals', ARRAY_N);
    foreach ($likes as $like) {
        $wpdb->query('UPDATE ' . $wpdb->prefix  . 'comment_rating SET ck_rating_up = ' . $like['vote_count_up'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
        $wpdb->query('UPDATE ' . $wpdb->prefix  . 'comment_rating SET ck_rating_down = ' . $like['vote_count_down'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
    }
}

i have tested every line with echo function.foreach line not running and i think $wpdb->get_results is wrong. please help me. Sorry for my bad english.

  • 写回答

1条回答 默认 最新

  • doucuo4413 2014-05-26 17:46
    关注

    i solve this. my table have 147,308 rows. problem is table rows number. i add LIMIT code for only get 1000 rows and remove every row after copy to another table.thanks.

    function comment_rating() {
        global $wpdb;
        $likes = $wpdb->get_results('SELECT * FROM ' . $wpdb->prefix . 'up_down_comment_vote_totals LIMIT 0, 1000', ARRAY_A);
        foreach ($likes as $like) {
        echo "id " . $like['comment_id'] . "<br>";
        $wpdb->query('UPDATE ' . $wpdb->prefix  . 'comment_rating SET ck_rating_up = ' . $like['vote_count_up'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
        $wpdb->query('UPDATE ' . $wpdb->prefix  . 'comment_rating SET ck_rating_down = ' . $like['vote_count_down'] . ' WHERE ck_comment_id = ' . $like['comment_id']);
        $wpdb->query('DELETE FROM ' . $wpdb->prefix  . 'up_down_comment_vote_totals WHERE comment_id =  ' . $like['comment_id']);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 socket通信实现多人聊天室疑惑
  • ¥15 DEV-C++编译缺失
  • ¥33 找熟练码农写段Pyhthon程序
  • ¥100 怎么让数据库字段自动更新
  • ¥15 antv g6 力导向图布局
  • ¥15 quartz框架,No record found for selection of Trigger with key
  • ¥15 锅炉建模+优化算法,遗传算法优化锅炉燃烧模型,ls-svm会搞,后面的智能算法不会
  • ¥20 MATLAB多目标优化问题求解
  • ¥15 windows2003服务器按你VPN教程设置后,本地win10如何连接?
  • ¥15 求一阶微分方程的幂级数