duanlan7903 2019-03-15 16:49
浏览 15

mysqli总和为两个日期之间的总和

I am wanting to sum the colum funds where date is between start and endate

I am getting error:

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in

PHP

*<?php

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

            $startdate = $_GET['startdate'];
    $enddate = $_GET['enddate'];

$ssql="SELECT sum(funds) as total FROM bets WHERE date BETWEEN '$startdate' AND '$enddate'";


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

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

mysqli_close($connection);
?>*

Further down within the same php script - this works 100% fine and shows the data as expected from query

$startdate = $_GET['startdate'];
    $enddate = $_GET['enddate'];


            $q = "select * from betFigures WHERE date BETWEEN '$startdate' AND '$enddate'";
  $query = mysqli_query($connection,$q);

        $x = 1;
                echo "<table class='table'><tr>";
                        echo "<th>date</th>";
                        echo "<th>funds</th>";
                        echo "<th>spent</th>";
                        echo "<th>return</th>";
                        echo "<th>profit</th>";
                        echo "<th>bets</th>";
                        echo "<th>wins</th>";
                        echo "<th>loss's</th>";
                        echo "<th>strike rate</th></tr>";

         while($res = mysqli_fetch_array($query)){

             $betfdate = $res['date'];
             $funds = $res['funds'];
             $spent = $res['spent'];
             $bfreturn = $res['return'];
             $profit = $res['profit'];
             $bets = $res['bets'];
             $wins = $res['wins'];
             $loss = $res['loss'];
             $strikerate = $res['strikeRate'];



             echo "<tr><td><p>".date("d-m-Y",strtotime($betfdate))."</p></td>"; 
             echo "<td><p>$funds</p></td>";  
             echo "<td><p>$spent</p></td>"; 
             echo "<td><p>$bfreturn</p></td>"; 
             echo "<td><p>$profit</p></td>"; 
             echo "<td><p>$bets</p></td>"; 
             echo "<td><p>$wins</p></td>";
             echo "<td><p>$loss</p></td>";
             echo "<td><p>$strikerate</p></td></tr>";   
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法