Results 1 to 3 of 3
I have some php scripts used to track time on a project on a LAMP server on a local machine. The person types his/her name, clicks Submit button to sign ...
- 06-22-2009 #1Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
php/mysql track time
I have some php scripts used to track time on a project on a LAMP server on a local machine. The person types his/her name, clicks Submit button to sign in and a Unix timestamp is stored in the database. Same thing for sign out. I have a name search script which prints to screen all sign in/sign out times for that person in format:
Login: smith,john: June 16, 2009 (10:32 AM)
Logout: smith,john: June 16, 2009 (1:17 PM)
I also have a time search script to search by a specific date which outputs the same information for that date in the above format. I have the script below which outputs the number of hours and/or minutes when a specific name and date are entered in this format:
smith, john Hours: 2, Minutes: 44
Not a very clean looking script but it does what I want. What I want to do is modify this script or create a new one to perform the same function, that is, compute the time signed in for each person by specific date entering only the date but don't really know where to begin. I've done some searching but I guess I may be out of my depth here.PHP Code:<?php
mysql_connect("localhost","username","password");
mysql_select_db("timesheet");
$day = $_POST["day"];
$month = $_POST["month"];
$year = $_POST["year"];
$search= $_POST["search"];
$SearchDateStart = mktime(0,0,0,$month,$day,$year);
$SearchDateStop = $SearchDateStart + 86400;
$result = mysql_query("SELECT name,datetime,timedate FROM hours WHERE datetime >= $SearchDateStart AND datetime < $SearchDateStop AND name LIKE '%$search%' ORDER BY name");
"<table border=1>\n";
while($r=mysql_fetch_array($result))
{
$name=$r["name"];
$datetime=$r["datetime"];
$timedate=$r["timedate"];
echo "$name";
}
?>
<?php
$result = mysql_query("SELECT name,timedate FROM hours WHERE timedate >= $SearchDateStart AND timedate < $SearchDateStop AND name LIKE '%$search%' ORDER BY name");
while($r=mysql_fetch_array($result))
{
$name=$r["name"];
$timedate=$r["timedate"];
}
$diff = $timedate-$datetime;
if ($diff > 3600){
echo "<td> Hours: " . intval($diff/3600);"</td>";
echo "<td>, Minutes: " . intval($diff%3600/60);"</td>";
}elseif ($diff <= 3600)
echo "<td> Minutes: " . intval($diff/60);"</td></tr>";
"</table>"
?>
- 06-22-2009 #2Just Joined!
- Join Date
- Jun 2009
- Posts
- 6
Sorry, I didn't understand what you want to do. Maybe because I'm French and not bilingual at all.
Does you script work ? If it does, what do you want to do another one for ?
- 06-22-2009 #3Linux Guru
- Join Date
- Oct 2007
- Location
- Tucson AZ
- Posts
- 1,939
It works. I enter a name (smith, john) as well as the date and it will give me output such as the following:
smith, john Hours: 2, Minutes: 44
What I want to do is get the output in hours and/or minutes for every person signed in on a particular day by entering that date. The script above will only do this for a particualr name/date combination entered.


Reply With Quote