I'm working on a HTML form that has a select menu that's driven from a PHP Array that is retrieved from a database to show a list of times that can be chosen for an event. Here's the array:
Array ( [9:00am] => 9:00am [9:30am] => 9:30am [9:45am] => 9:45am [10:00am] => 10:00am [10:30am] => 10:30am [10:45am] => 10:45am [11:00am] => 11:00am [11:30am] => 11:30am [11:45am] => 11:45am [12:00pm] => 12:00pm [12:30pm] => 12:30pm [12:45pm] => 12:45pm [1:00pm] => 1:00pm [1:30pm] => 1:30pm [1:45pm] => 1:45pm [2:00pm] => 2:00pm [2:30pm] => 2:30pm [2:45pm] => 2:45pm [3:00pm] => 3:00pm [3:30pm] => 3:30pm [3:45pm] => 3:45pm [4:00pm] => 4:00pm [4:30pm] => 4:30pm [4:45pm] => 4:45pm [5:00pm] => 5:00pm [5:30pm] => 5:30pm [5:45pm] => 5:45pm [6:00pm] => 6:00pm [-] => - )
The problem is that existing values in the corresponding field in the database are not showing as selected as they don't match one of the options in the array/select menu. For example when you retrieve an event record from the database via PHP and display the value for the event time field it appears as "11:45:00", which doesn't match any of the options in the Select menu so this doesn't show as "selected".
I'm not sure how I can easily convert a time in the format:
11:45:00
to the corresponding time in the format that matches the select menu:
11:45am