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);
?>

Link to comment
https://forums.phpfreaks.com/topic/277989-the-sum-of-my-problem/
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.

I am trying

$thesum = $result['value_sum']->fetch_field();

or

$thesum = $result->fetch_field();

right before

echo $thesum;
$result->close;

this the right direction?

none of those format looks like the one that is showed in the php manual... read it again.... or you can try http://www.php.net/manual/en/mysqli-result.fetch-assoc.php too

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.