A user can enter a location via an edit form once they are registered with my site. The drop down menus for the locations is populated by an array so that the value is set as a number and the text is set as the location name so that is easy to complete.
The corresponding number is then stored in the user's profiles table as their location so that I can display it on their profile, search results and anywhere it is needed.
I obviously don't want to display the number - but rather the corresponding location name.
I have a table (frmLocations
) that lists out the locations and assigns an ID To them, the ID is the same that is quoted in my array that populates the form field.
I can retrieve and loop out the location value but want to be able to match the number up with the ID from the frmLocations
table and echo out the location_city
column instead of the number.
It is complicated because I think I need to reference two separate tables to complete the query.
My frmLocations
table is made up of id
, location_city
, location_county
, location_country
.
The field in my profiles
table that stores the data for location is profiles_city
.
An example of an array entry;
$location_city_frm = array(
25=>'Maidenhead',
489=>'Manchester',
493=>'Oldham',
502=>'Salford');
My loop for displaying the location in the profile page;
<?php foreach($locations as $location): ?>
<?php if(!empty($location['location_city'])){ ?>
<div><strong>City</strong> <?php echo $location['location_city'] ?></div>
<?php } ?>
<?php endforeach ?>
Any help would be appreciated.