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)
//Agent create appointment for himself Agent add through a form that has Date: …, starttime: …., averagetime: …., endtime:…..
i wrote query to select from appointemnt the agent appointment time.
i used while() for the stmt-> excute
Problem 1: while loop make it repeat same date and time so many times. I tried using foreach() or for(), it is not working. I dont know if am using it wrongly or just that it wont work.
Problem 2: what i want to achieve is that the table should; for every date, role1 start time, role2 start time + average time, role 3 role2time + average time. so the output will be like peter 22/08 4:00 peter 22/08 4:30, peter 22/08 5:00 etc
$sql = "SELECT * FROM agent_schedule_table INNER JOIN agent ON agent.agent_id = agent_schedule_table.agent_id INNER JOIN property ON property.agent_id = agent.agent_id INNER JOIN rent_interest ON rent_interest.Property_number = property.Property_number WHERE (agent_schedule_table.agent_schedule_date >= '$todaysdate' AND property.Property_number = '".$_SESSION["apartment_number"]."') ORDER BY agent_schedule_table.agent_schedule_date ASC"; $stmt = $pdo->prepare($sql); $stmt ->execute(array()); $rows = array(); while ($row = $stmt->fetch(PDO::FETCH_ASSOC) ) { $result = $row; }
Advertisement
Answer
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"];