Jump to content

The SUM of my problem


rusking

Recommended Posts

I seem to have most of this complete as I get results from the database in the table but can add some values together. The error I recieve is "Select returned 1 rows." I am trying to get a return of a column added (the column contains numbers) Any guidance is appreciated, I'm switching to PHP as my main language but still new to it (coming from AUTOIT)


 




 I'm using MAMP to locally server (MYSQL,Apache etx) is use this to build my sites then host them live. The SQL server has a structure as such:  localhost  » dot.gifKNTDEBITS  » dot.gifInsurance



<?php
$con=mysqli_connect("localhost","root","root","KNTDebits");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result4 = mysqli_query($con,"SELECT * FROM DanvilleLocation");



//Table 4 Start
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>";

if ($result = $con->query("SELECT SUM(STATECOV) AS value_sum FROM Insurance")) {
printf("Select returned %d rows.\n", $result->num_rows);

/* free result set */
echo $result;
$result->close();
}

echo "</table>";
echo $result;



mysqli_close($con);
?>

Edited by rusking
Link to comment
Share on other sites

The error I recieve is "Select returned 1 rows."

 

  that is not an error... is just the result of the printf() that you have after the IF... problem is that immediately after you are trying to "echo" a result set (echo $result) .. what you have to do is fetch the result and then echo your "value_sum" value.

Edited by mikosiko
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.