Page 1 of 1

timeDiff function

Posted: Tue Jan 31, 2012 2:43 am
by mnyore
I have a table

id name stime etime

1 kip 10:10:00 11:10:05
2 too 10:15:05 11:15:00
3 bii 10:25:25 12:00:08


Am using the timediff() function in mysql I just want to display the name & time taken to run. How should I write the echo statements? its working on mySQL but has problems running php

The echo code below only echos the names but doesn't echo duration taken.

<?php
$con = mysql_connect("localhost","root");
$db = mysql_select_db("irun",$con);
$sql = mysql_query("select names, timediff(`etime`,`stime`) from irunner");

while($row=mysql_fetch_array($sql))
{
echo "".$row['names']."";
echo "".$row[timediff(`etime`,`stime`)]."
}

Re: timeDiff function

Posted: Tue Jan 31, 2012 3:17 am
by mnyore
It only echoes the column names but doesnt work out the time difference between start and end time.

Re: timeDiff function

Posted: Tue Jan 31, 2012 9:03 am
by Robertology
It is sometimes easier to alias a column in a situation like that.

Code: Select all

select names, timediff(`etime`,`stime`) as time_diff from irunner
Then you can reference it like so

Code: Select all

$row['time_diff']