dwesdijk Posted October 27, 2008 Share Posted October 27, 2008 Hi all, I'm working on a page which displays some computers to repair. Each repair has a sub page where employees can add a comment. All comments are saved in the mysql-table with a time. That displays the time how long the employee was busy with the repair. In that subpage it has to display a sum of all the hours. This is the query to count the hours: 419 $query = "SELECT sum(hourcount) FROM ds_comment WHERE recall_id = $recall_id"; 420 $hourtotal = $mysqli->query($query); This is where it has to be shown: 463 echo " <td class='table_cel_2'>".$hourtotal." </td>"; This is the error i get: Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\installatieruimte\index.php on line 463 Tabel: id recall_id comment date time hourcount employee 55 38 23 39747 16:15:18 00:30:00 Martin van der Meer 53 38 Test 39747 16:04:09 00:20:00 David Wesdijk 54 38 Test2 39747 16:04:38 02:40:00 David Wesdijk What does it have to do: Make a sum of the 'hourcount' with the same 'recall_id' Could you help me out? Thanks in advance, David Wesdijk The Netherlands Link to comment https://forums.phpfreaks.com/topic/130290-counting-hours-from-mysql-table/ Share on other sites More sharing options...
Barand Posted October 27, 2008 Share Posted October 27, 2008 $mysqli->query() returns a result object $result = $mysqli->query("SELECT SUM(colname) as tot FROM tablename"); $row = $result->fetch_assoc(); echo "Total : {$row['tot']}"; Link to comment https://forums.phpfreaks.com/topic/130290-counting-hours-from-mysql-table/#findComment-675989 Share on other sites More sharing options...
PFMaBiSmAd Posted October 27, 2008 Share Posted October 27, 2008 To sum time you must do something like the following - SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(time_col))) FROM tbl_name; Link to comment https://forums.phpfreaks.com/topic/130290-counting-hours-from-mysql-table/#findComment-675994 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.