<?php

                    $con = mysql_connect("localhost","root","");
                    if (!$con)
                         {
                             die('Could not connect: ' . mysql_error());
                         }

                            mysql_select_db("ms", $con);
                            $time1 = $row['timein'];
                            $time2 = $row['timeout'];

                            $sql = mysql_query("SELECT employees.*, timetable.*  FROM employees INNER JOIN timetable ON
                                                 employees.id = timetable.id WHERE timetable.in_time BETWEEN employees.timein AND employees.timeout ");

                     echo "<table width='734'>
                        <tr>
                            <th width='49' scope='col'>Employee ID</th>
                            <th width='49' scope='col'>Lastname</th>
                            <th width='49' scope='col'>Firstname</th>
                            <th width='49' scope='col'>Department</th>
                            <th width='49' scope='col'>Time In</th>
                            <th width='49' scope='col'>Time Out</th>
                        </tr>";

                     while ($row = mysql_fetch_array($sql))
                         {  

                        echo "<tr>";
                             echo "<td class='align-center'>&nbsp" . $row['id'] . "&nbsp</td>";
                             echo "<td>&nbsp" . $row['Lastname'] ."&nbsp</td>";
                             echo "<td>&nbsp" . $row['Name'] . "&nbsp</td>";
                             echo "<td>&nbsp" . $row['Department'] . "&nbsp</td>";
                             echo "<td class='align-center'>&nbsp" . $row['in_time'] . "&nbsp</td>";
                             echo "<td class='align-center'>&nbsp" . $row['out_time'] . "&nbsp</td>";
                        echo "</tr>";

                        };
echo "</table>";

mysql_close($con);
?>

Recommended Answers

All 11 Replies

Member Avatar for LastMitch

@shhh

Can you post your table? So I can see what you have. The code you provide is a JOIN but having to see the actually table will make more sense!

timetable

id | date | in_time | out_time
C003 2012-11-14 2012-11-14 9:17:18 2012-11-14 9:17:18

id Name Middlename Lastname Email Homeaddress Birthdate Contactnumber Department username Password Profileimage timein timeout branchcode C003 Kevin Dagdayan Lee kevindagdayanlee@gmail.com Danube 116 Riverfront Pasig City 1990-02-11 09244587236 MIS pinkpapi cGFzc3dvcmQ= 9.png 08:00:00 am 11:00:00 am 0003 Edit Delete C002 Harold San Francisco harodlo@yahoo.com Calooocan City 1992-06-29 09275618930 Bonding haroldo cGFzc3dvcmQ= 4.png 10:00:00 am 11:00:00 am 0002 Edit Delete C001 Maria Celine Guevara Cinco mariacelinecinco@gmail.com 13th Street Northgate Village New Manila Quezon Ci... 1992-11-21 09158368338 MIS celine21 Z29kc2xvdmU=

i need it to display late employees ~ Thank you

what is in time, is it same for all or is it diffent for all

@urtrivedi - different for all

This query shows all record who come after their standard in time.

                       $sql = mysql_query("SELECT employees.*, timetable.*  FROM employees INNER JOIN timetable ON
                                             employees.id = timetable.id WHERE timetable.in_time > str_to_date(concat(timetable.date,' ',employees.timein)  ,'%Y-%m-%d %r')");

@urtrivedi - no result

Member Avatar for LastMitch

@shhh

Are connected to the database?

@lastmitch - yes ~ i want to select employees whos late .but each employees has a different default time on time in .

Member Avatar for LastMitch

i want to select employees whos late .but each employees has a different default time on time in .

urtrivedi - wrote the query example because you said different for all and it made sense but now it's no result and now you want employees whos late?

Can you just add another row called late then you can JOIN timeout and timein? Right now, it's very complicated because how can you put late on an employee base on your code? You need to create if & else statement and another query to do select the employee who is late.

post few reocordds from employee and few from timetable(where some ar lare and some are not late)

do not past combine query result, just paste 2 separte table records.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.