rusking Posted May 14, 2013 Share Posted May 14, 2013 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 » KNTDEBITS » Insurance <?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 More sharing options...
mikosiko Posted May 14, 2013 Share Posted May 14, 2013 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. Link to comment https://forums.phpfreaks.com/topic/277989-the-sum-of-my-problem/#findComment-1430030 Share on other sites More sharing options...
rusking Posted May 14, 2013 Author Share Posted May 14, 2013 Ok i see, i eblive the command im looking for to fetch is ->fetch_field(); if im incorrect please let me know. I do find it slighly difficult to find where to place it...im trying to learn from this url http://www.php.net/manual/en/mysqli-result.fetch-field.php Link to comment https://forums.phpfreaks.com/topic/277989-the-sum-of-my-problem/#findComment-1430042 Share on other sites More sharing options...
rusking Posted May 14, 2013 Author Share Posted May 14, 2013 I am trying $thesum = $result['value_sum']->fetch_field(); or $thesum = $result->fetch_field(); right before echo $thesum; $result->close; this the right direction? Link to comment https://forums.phpfreaks.com/topic/277989-the-sum-of-my-problem/#findComment-1430043 Share on other sites More sharing options...
mikosiko Posted May 14, 2013 Share Posted May 14, 2013 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 Link to comment https://forums.phpfreaks.com/topic/277989-the-sum-of-my-problem/#findComment-1430051 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.