drfkl66684 2016-08-22 08:10
浏览 69
已采纳

如何在php中将数组划分为两个索引

i am fetching time from mysql_db below is my code...

$sql="SELECT * from employee_timings where emp_timing_date='$date'";
$query=mysql_query($sql);
$array=array();
while ($result=mysql_fetch_array($query)) {
    # code...
    $emp_starting_time=$result['emp_in_time'];

}

below is my table from which i am fetching the values...enter image description here the issue is it gives me result in following format 11:00:0014:00:00 and when i echo this

 echo $emp_starting_time[0];

it outputs the first character of first time i.e 1 and second time i.e 1 what i want is that whenever i echo

    $emp_Starting_time[0]

it should display the whole 1st starting_time which is 11:00:00 kindly tell me how to achieve that

  • 写回答

1条回答 默认 最新

  • duanpei4455 2016-08-22 09:11
    关注

    You give $emp_starting_time variable the value $result['emp_in_time'];. It contains the result you are looking for in a string format. When you write echo $emp_starting_time[0];, it returns you the fist charracter of this string. Try echo $emp_starting_time;

    UPDATE

    You can create an array outside of the loop and then push in it each value:

    $array=array();
    while ($result=mysql_fetch_array($query)) {
        # code...
        array_push($array, $result['emp_in_time']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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