PHP get sum of SQL table (Know im close here) -


i have mamp (local hosted sql,web etc server) database name :nktdebits table name :insurance , column on table statecov know im close still black in field should generate total, got idea?

$result = mysqli_query($con,"select * insurance"); $result2 = mysqli_query($con,"select * office"); $result3 = mysqli_query($con,"select * richmondlocation"); $result4 = mysqli_query($con,"select * danvillelocation"); $result5 = mysql_query('select sum(statecov) statecov_sum insurance');    echo "<table border='1'> <tr> <th>truck number</th> <th>vin</th> <th>make</th> <th>model</th> <th>state coverage</th> <th>comprehinsive coverage</th> <th>property damage/th> <th>personal injury</th> </tr>";  while($row = mysqli_fetch_array($result))   {   echo "<tr>";   echo "<td>" . $row['tnum'] . "</td>";   echo "<td>" . $row['vin'] . "</td>";   echo "<td>" . $row['make'] . "</td>";   echo "<td>" . $row['model'] . "</td>";   echo "<td>" . $row['statecov'] . "</td>";   echo "<td>" . $row['compre'] . "</td>";   echo "<td>" . $row['propdmg'] . "</td>";   echo "<td>" . $row['prsinj'] . "</td>";   echo "</tr>";   } echo "</table>";   //table 2 start str_repeat('&nbsp;', 5); // adds 5 spaces echo "<table border='5'>  <tr> <th>richmond</th> <th>date</th> <th>payment</th> <th>payer</th> </tr>";  while($row3 = mysqli_fetch_array($result3))  {   echo "<tr>";   echo "<td>" . $row3[''] . "</td>";   echo "<td>" . $row3['date'] . "</td>";   echo "<td>" . $row3['payment'] . "</td>";   echo "<td>" . $row3['payer'] . "</td>";   echo "</tr>";   } echo "</table>";  //table 4 start str_repeat('&nbsp;', 5); // adds 5 spaces echo "<table border='5'>  <tr> <th>danville</th> <th>date</th> <th>payment</th> <th>payer</th> </tr>";  while($row4 = mysqli_fetch_array($result4))   {   echo "<tr>";   echo "<td>" . $row4[''] . "</td>";   echo "<td>" . $row4['date'] . "</td>";   echo "<td>" . $row4['payment'] . "</td>";   echo "<td>" . $sum . "</td>";   echo "</tr>";   } echo "</table>";  //table 5 start  echo "<table border='5'>  <tr> <th>total</th> </tr>";  $result = mysql_query('select sum(statecov) value_sum insurance');  $row = mysql_fetch_assoc($result);  $sum = $row['value_sum'];  while($row = mysql_fetch_assoc($result));    {   echo "<tr>";   echo "<td>" . $sum . "</td>";   echo "</tr>";   } echo "</table>";   mysqli_close($con); ?>  

you need group go along sum. don;t know enough table let know column should use this.

you should handling potential error cases whenn query database, see when getting database/query errors.

you should use mysqli or pdo instead of deprecated mysql_* functions.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -