dourang20110122 2019-03-08 12:36
浏览 55

MySQLi列总和为一个查询而不是另一个查询[重复]

This question already has an answer here:

I am trying to sum the total value of one column....

I have it working for doing sum of other columns, yet this colum wont sum and I don't get a value echo'd.

Anyone have any suggestions why, the formatting of the colum return is the exact same as profit (decimal 5,2)

PHP - Working one

 <div class="col-md-2 col-md-2-2">
                    <div class="card mt-5">
                        <div class-title>
                        <h3 role="button" class="bg-secondary text-white text- 
   center py-3">Stake Placed<br></h3>                           
                        </div>
                        <div class="card-body">
    <table class='table table-bordered'>
    <?php

    $connection = mysqli_connect("******", "******", 
    "******", "******");
    if (!$connection) {
        die("Database connection failed: " . mysqli_connect_error());
    }

             $Date = '2019-03-11'; 

    $ssql="SELECT sum(stakePlaced) as total FROM bets WHERE betDate = '$Date'";


    $sresult = mysqli_query($connection, $ssql);

    while ($srow = mysqli_fetch_assoc($sresult))
    { 
    echo "<tr>";
    echo "<td class='text-center'>£".$srow['total'] . "</td>";
    echo "</tr>";
    }

    mysqli_close($connection);
    ?>
    </table>
                        </div>


                    </div>
                </div> 

PHP - Not Working one

            <div class="col-md-2 col-md-2-2">
                    <div class="card mt-5">
                        <div class-title>
                        <h3 role="button" class="bg-secondary text-white text- 
    center py-3">Actual Return<br></h3>                         
                        </div>
                        <div class="card-body">
    <table class='table table-bordered'>
    <?php

    $connection = mysqli_connect("******", "******", 
    "******", "******");
    if (!$connection) {
        die("Database connection failed: " . mysqli_connect_error());
    }

             $Date = '2019-03-11'; 

    $test = "SELECT sum(return) as total FROM bets WHERE betDate = '$Date'";

    $testr = mysqli_query($connection, $test);

    while ($testrow = mysqli_fetch_assoc($testr)) 

    { 
    echo "<tr>";
    echo "<td class='text-center'>£".$testrow['total'] . "</td>";
    echo "</tr>";
    }

    mysqli_close($connection);
    ?>
    </table>

result screenshottable screenshot

</div>
  • 写回答

1条回答 默认 最新

  • dongpo1203 2019-03-08 12:45
    关注

    return is reserved keyword in mysql. Either change the column name or you should use ticks when using that column name

    sum(`return`) 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100