This code is giving error. I have gone through previous questions. I have used gettype() and it shows that my data is integer. I have tried to convert it to string by using strval() but it didnt work. I saw this but in dont know how this can be implemented with my code.
sugested similar questions talk about undefined variables. My problem not undefine but that its value type. variables are defined. It is stored in db as string but when i check its variable type using gettype(), it is an integer. and it seems foreach() doesnt work with integer.
If anyone can help please. i am still in the learning stage.
foreach($schedule_data as $schedule_row)
{
$end_time = strtotime($schedule_row["agent_schedule_end_time"] . ':00');
$start_time = strtotime($schedule_row["agent_schedule_start_time"] . ':00');
$total_agent_available_minute = ($end_time - $start_time) / 60;
$average_inspection_time = $schedule_data["average_inspection_time"];
}
i wrote query
SELECT * FROM agent_schedule_table
WHERE agent_schedule_id = '$agent_schedule_id'
data stored in $schedule_data
var_dump ()
array(8) {
["agent_schedule_id"]=> int(18)
["agent_id"]=> string(7) "S1O0NWE"
["agent_schedule_date"]=> string(10) "2022-08-18"
["agent_schedule_day"]=> string(8) "Thursday"
["agent_schedule_start_time"]=> string(5) "08:35"
["agent_schedule_end_time"]=> string(5) "22:35"
["average_inspection_time"]=> int(60)
["agent_schedule_status"]=> string(6) "Active"
}
foreach()
var_dump($end_time); = int(1660595700)
CodePudding user response:
I don't think you need a loop. $schedule_data
is an associative array, just access the element from there, not from a nested element.
$end_time = strtotime($schedule_data["agent_schedule_end_time"] . ':00');
$start_time = strtotime($schedule_data["agent_schedule_start_time"] . ':00');
$total_agent_available_minute = ($end_time - $start_time) / 60;
$average_inspection_time = $schedule_data["average_inspection_time"];