0

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 screenshot table screenshot

Vidhyut Pandya
  • 1,605
  • 1
  • 14
  • 27

1 Answers1

0

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

sum(`return`) 
Qirel
  • 25,449
  • 7
  • 45
  • 62
kami s
  • 11
  • 4