简体   繁体   English

MySQL从用户ID获取积分

[英]MySQL Get Points from user id

Note: new to mysql 注意:mysql新手

I am trying to get points from user id ( please view attached table image) 我正在尝试从用户ID获取积分(请查看所附的表格图片)

在此处输入图片说明

qa_ is my custom table prefix qa_是我的自定义表前缀

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. 我正在使用wordpress,想要获取当前登录的用户ID,并希望将其传递,以便可以获取该用户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'].')';

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

    return '(points '.$points->points.')';

}

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM