I have a code to count student id who has "in" and "out" all I want is to get the student id who have "in" and "out",if the student have only "in" I want to execute this code
INSERT INTO
log
(stud_id
,date_log
,time_log
,ampm
,status_log
,status
) VALUES ('student id who has "in" only', 'currentdate', 'current time', 'PM', 'out', 1),
This is my existing code.
$total=mysql_query("SELECT count(stud_id) as mycount, stud_id, date_log FROM `log`
WHERE date_log >= CURRENT_DATE() and ampm='pm' GROUP BY stud_id");
$d=mysql_fetch_assoc($mycount);
</div>
SQL doesn't support WHERE statements in INSERTs. Instead you could pull the information from the database doing a SELECT query and then do an IF statement to do your inserts. As so:
$results = mysql_query("SELECT * FROM log WHERE date_log >= CURRENT_DATE() and ampm='pm' GROUP BY stud_id");
while($row = mysql_fetch_array($results)) {
if ($row['status_log'] == "in") {
mysql_query("INSERT INTO log ( stud_id, date_log, time_log, ampm, status_log, status) VALUES ('".$row['stud_id'].", 'currentdate', 'current time', 'PM', 'out', 1)");
}}
NOTE I wrote this with assumptions to how your database is filled out. I HIGHLY doubt it will be a copy and paste code.
Source of INSERT information: http://dev.mysql.com/doc/refman/5.5/en/insert.html
EDIT: Updated because of syntax error