douhan0562 2015-08-18 03:07
浏览 38
已采纳

php获取有“in”和“out”的学生ID [关闭]

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>
  • 写回答

1条回答 默认 最新

  • douxing1353 2015-08-18 03:32
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计