drsh30452 2016-12-29 12:34
浏览 33
已采纳

Php如何选择存储在数据库中的时间组合框

I have the time combobox which is showing the time properly and storing in database.

How to select the time in that list which is stored in the database.

In the database the stored time is 02:30 and in this all times are there i want to select the 02:30 from this list this time list is automatically populated.

Any help will be appreciated.

My Code

<select name="open" class="form-control" style="width: 112px;">
<?php
    $start=strtotime('00:00');
    $end=strtotime('23:59');
    for ($halfhour=$start;$halfhour<=$end;$halfhour=$halfhour+30*60) {
printf('<option value="%s">%s</option>',date('H:i',$halfhour),date('g:i a',$halfhour));
    }
?>
</select>
  • 写回答

1条回答 默认 最新

  • donglan8870 2016-12-29 13:07
    关注

    Well i have found the solution.

    $user   =   mysql_query("
    select * from timing where sr_id = '".$_GET['id']."'
    ");
    $usert  =   mysql_fetch_assoc($user);
    $open   =   $usert['open'];
    
    $start=strtotime('00:00');
    $end=strtotime('23:59');
    for ($halfhour=$start;$halfhour<=$end;$halfhour=$halfhour+30*60) {
    
    $ttt=date('H:i',$halfhour);
    
    if ($open == $ttt){
    printf('<option selected value="%s">%s</option>',date('H:i',$halfhour),date('g:i a',$halfhour));
    }else{
    printf('<option value="%s">%s</option>',date('H:i',$halfhour),date('g:i a',$halfhour));
    }
    }
    

    It will select the time stored in database from this timing list by using $open and making variable of date('H:i',$halfhour) from that time code $ttt=date('H:i',$halfhour); of inside if condition if ($open == $ttt){ in that time code.

    Inspired by @Fred-ii-

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题