doushitang4276 2012-11-21 00:19
浏览 35
已采纳

在用户输入日期和时间时修改mysql DB

im working on a quiz web application in php and mysql, i have a user table and quizes table, the admin has access to a table with the quizes name and a checkbox besides every quiz...

lets say theres 10 quizes numbered from 1 to 10, each one of this corresponds to a quiz in mysql,

when you click on the checkbox besides a quiz and hit SEND, that particular quiz is available to a certain user (that on a previous page i already chose) but on that same page i want to put input fields with a time and a date, and that quiz will only be available from the present time to the input date and time....

the user table has a column for every quiz named is_available with default to zero, i want that value change to 1 when that user and quiz are chosen and change back to zero when the date has passed..

i have been thinking how to do this but i have no clue, any ideas or guidelines of where to go or how to start doing this??? i need heeeelp! hehe

  • 写回答

2条回答 默认 最新

  • doutan2111 2012-11-21 03:32
    关注

    You can do this using MySQL, PHP, and CRON

    First, create a relational table -

    CREATE TABLE `test_expiry` (
        `userid` int(2) unsigned NOT NULL,  // user that is taking the test
        `testid` int(2) unsigned NOT NULL,  // test number
        `expires` datetime NOT NULL);  // date/time test will expire
           //change names/types as needed / to match your db structure
    

    Second, when setting is_available = 1, add that test to the test_expiry table

    INSERT INTO `test_expiry` (`userid`,`testid`,`expires`) VALUES (:userid,:testid,:expires)
    

    Third, create a php page that will update is_available = 0, if date/time has past.

    SELECT `userid`, `testid` FROM `test_expiry` WHERE `expires` < NOW()
    foreach row above ...
    UPDATE `tests` SET `is_available` = 0 WHERE `userid` = :userid AND `testid` = :testid
    

    And last, set up a cron job-

    * * * * *  [/path/to/php/]php /path/to/your/script/update.php
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。