I had this question after viewing SQL inner join confusion
When editing a record, there is a dropdown for location. Ideally, I would like the location chosen in the initial insert record to be the text you see in the dropdown so when the record is updated, it doesn't change the location because it is on the default record from the SQL query. So, if it is alphabetical and when you signed up you chose United States, when you go to update the record, the dropdown should still show United States as the selected record and not the first record in the alphabet i.e.: Africa for example. This would obviously be to prevent them pressing the update button and unwillingly the database record changes from United States to Africa.
I figured out the part that I need to show the initial selected location as per below. My problem is that it only shows one record, the initial selection. Is it possible to list all the other locations beneath it in case the user does want to change their location? Or is there a better way to handle this?
echo "<select name='locations' class='selectpicker' data-title='Select Location' data-style='btn-default btn-block' data-menu-style='dropdown-blue'>";
$stmt = $link->prepare("SELECT location.location_name, service_providers.sp_location FROM service_providers INNER JOIN location ON service_providers.sp_location = location.location_id AND service_providers.service_provider_id = ?");
echo "<option value='$sp_location'>" . sanitize($location_name) ."</option>";
echo " </select>";