Find the answer to your Linux question:
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 ...
  1. #1
    Linux 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

    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>&nbsp;&nbsp;Hours:&nbsp;&nbsp;" intval($diff/3600);"</td>";
       echo 
    "<td>,&nbsp;&nbsp;Minutes:&nbsp;&nbsp;" intval($diff%3600/60);"</td>";
    }elseif (
    $diff <= 3600)
       echo 
    "<td>&nbsp;&nbsp;Minutes:&nbsp;&nbsp;" intval($diff/60);"</td></tr>";
    "</table>"   
    ?>
    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.

  2. #2
    Just 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 ?

  3. #3
    Linux 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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...