$wpdb->get_results not working

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.

Related posts

Leave a Reply

1 comment

  1. 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']);
        }
    }