MySQL Get Points from user id

Note: new to mysql

I am trying to get points from user id ( please view attached table image)

Read More

enter image description here

qa_ is my custom table prefix

I am using wordpress and want to get current logged in user id and want to pass it so can get points of that user id.

Here what I am trying but nothing work

function qa_points($userid){
    global $wpdb;
    $prefix = 'qa_';
    $points = $wpdb->get_results("
        SELECT *
        FROM ${prefix}userpoints
        WHERE points = userid
    "); 

    return '(points '.$points['points'].')';

}

Related posts

Leave a Reply

2 comments

  1. function qa_points($userid){
        global $wpdb;
        $prefix = 'qa_';
        $points = $wpdb->get_row("
            SELECT points
            FROM ".$prefix."userpoints
            WHERE userid = $userid
        "); 
    
        return '(points '.$points->points.')';
    
    }
    
  2. If you want to select the points from a user, you have to select the correct user:

    $points = $wpdb->get_results("
            SELECT *
            FROM " . $prefix . "userpoints
            WHERE userid = $userid");