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']);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?