Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中如何跟随用户id获取MySQL列的和?_Php_Sql - Fatal编程技术网

在PHP中如何跟随用户id获取MySQL列的和?

在PHP中如何跟随用户id获取MySQL列的和?,php,sql,Php,Sql,我在一个表中有一列,我想在“userid=3”之后得到PHP中MySQL列的总和。但它不起作用。下面是我的代码: <?php $sql_select_point = 'SELECT SUM(total_amount) FROM bp_roi WHERE user_id = ' . $user_id; // when I login, $user_id will store my user id number. Now my login user_id is 3.

我在一个表中有一列,我想在“userid=3”之后得到PHP中MySQL列的总和。但它不起作用。下面是我的代码:

     <?php
    $sql_select_point = 'SELECT SUM(total_amount) FROM bp_roi WHERE user_id = ' . $user_id; // when I login, $user_id will store my user id number. Now my login user_id is 3.

    $query_select_point = db_conn_select($sql_select_point);
    foreach($query_select_point as $rs_select_point) {
    $bonus_point = $rs_select_point; //I want to store and get sum of MySQL column in $bonus_point
    }

    ?>


      <div class="form-group">
                        <label for="recipient-name" class="col-form-label">Bonus Point Balance:<span style="color:red;">&nbsp;*</span></label>
                        <div class="col-form-label">
                            <input class="form-group form-control" name="bonus_point" id="bonus_point" value="<?php echo $bonus_point; ?>" readonly></input> //I can't echo $bonus_point in the input.
                        </div>
                    </div>

积分余额:*

让我们向列中添加
别名
,并根据
索引
获取列值

<?php
    $sql_select_point = 'SELECT SUM(total_amount) as tAmount FROM bp_roi WHERE user_id = ' . $user_id; 

    $query_select_point = db_conn_select($sql_select_point);
    foreach($query_select_point as $rs_select_point) {
        $bonus_point = $rs_select_point['tAmount'];    
    }
?>

让我们向列中添加
别名
,并根据
索引
获取列值

<?php
    $sql_select_point = 'SELECT SUM(total_amount) as tAmount FROM bp_roi WHERE user_id = ' . $user_id; 

    $query_select_point = db_conn_select($sql_select_point);
    foreach($query_select_point as $rs_select_point) {
        $bonus_point = $rs_select_point['tAmount'];    
    }
?>


谢谢你回答我的问题。你的回答非常正确。谢谢你回答我的问题。你的回答非常正确。