rusking Posted May 14, 2013 Share Posted May 14, 2013 (edited) 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); ?> Edited May 14, 2013 by rusking Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 14, 2013 Share Posted May 14, 2013 (edited) 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 May 14, 2013 by mikosiko Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
rusking Posted May 14, 2013 Author Share Posted May 14, 2013 (edited) I am trying $thesum = $result['value_sum']->fetch_field(); or $thesum = $result->fetch_field(); right before echo $thesum; $result->close; this the right direction? Edited May 14, 2013 by rusking Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.