my query is very simple.
I have a table containing name, id, date, time, in, out
all i want php to check if
salman, 001, 12/12/2012, 12:12:12, 1, 0
then insert
salman, 001, 12/12/2012, 05:12:12, 0, 1
only in and out value need to change depending if employee is in then give value in = 0 and out = 1
else if employee is out then give value to in = 1 and out = 0
i’m stuck at some place
$insertqr = mysql_query("SELECT * FROM at_daily where daily_qr = '".$q."' and daily_date = '$today' and daily_in = '0'");//'".$today."'");
$daily = mysql_fetch_array($insertqr);
if($daily['daily_in'] == 0){
mysql_query("INSERT INTO at_daily (daily_name, daily_qr, daily_date, daily_time, daily_in, daily_out)
VALUES ('$name', '$q', '$today', '$ttime', '$myzero', '$myone')");
echo "record entered of In";
}
else if($daily['daily_in'] == 1)
{
mysql_query("INSERT INTO at_daily (daily_name, daily_qr, daily_date, daily_time, daily_in, daily_out)
VALUES ('$name', '$q', '$today', '$ttime', '$myone', '$myzero')");
echo "record entered of Out";
}
I would recommend to create a single column called status instead of daily_in and daily_out columns. Use 1 for in and 0 for out in status. that way u just have to toggle between 0 and 1 using an update query.
To toggle a value, we can make use of the common SQL control flow function IF. The IF function takes three parameters, first the test expression, the second the term to return if the test expression is true and the third being term to return if the test expression fails.
UPDATE
tableSETcolumn= IF(column= 1, 0, 1) WHEREid= ‘userid’