timeDiff function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mnyore
Forum Newbie
Posts: 2
Joined: Tue Jan 31, 2012 2:26 am

timeDiff function

Post 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`)]."
}
mnyore
Forum Newbie
Posts: 2
Joined: Tue Jan 31, 2012 2:26 am

Re: timeDiff function

Post by mnyore »

It only echoes the column names but doesnt work out the time difference between start and end time.
Robertology
Forum Newbie
Posts: 3
Joined: Fri Jan 27, 2012 11:31 am

Re: timeDiff function

Post 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']
Post Reply