在PHP中如何跟随用户id获取MySQL列的和?
我在一个表中有一列,我想在“userid=3”之后得到PHP中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.
<?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;"> *</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'];
}
?>
谢谢你回答我的问题。你的回答非常正确。谢谢你回答我的问题。你的回答非常正确。