I have a column call time_utilization in table. This contains the values in HH:MM:SS and its datatype is varchar. If it is required to change the datatype to time, I'll willing to do so.
I am trying to add the total time in this column. I tried the below thing and it didn't work. Any help is appreciated.
$qry = "SELECT SEC_TO_TIME(SUM(SECOND(time_utilization))) FROM tracker";
$result=mysql_query($qry) or die (mysql_error());
$row = mysql_fetch_array($result);
echo $row;
The SECOND() function returns the seconds part, not total seconds. For example, SECOND('01:26:33') returns 33, not 5193. To convert a time to total seconds, use TIME_TO_SEC().
$qry = "SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(time_utilization))) FROM tracker";
$result=mysql_query($qry) or die (mysql_error());
$row = mysql_fetch_array($result);
echo $row;
array mysql_fetch_array ( resource $result [, int $result_type = MYSQL_BOTH ] )
Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
if you want to see the result you must use $row[0] or similar...
change your "echo $row" for var_dump($row) to see the values.