After sleeping on it, my head is already spinning with this one.
I'm new to PHP and to be honest don't really know what I'm doing, just winging it!
I'll do my best to explain my problem ALL help is greatly appreciated.
My Database containsthe fields 'linkname' and 'linklocation'.
Each row of these fields is a Main Menu link on a website.
The idea is to create a drop down menu within the website admin pages.
This drop down will enable the user to select and save the 'linklocation' into the database as 'sitehome'.
'sitehome' will then be accessed as a variable, automatically redirecting the vistor to the admin's desired Home Page or 'linklocation'.
I have managed to populate the drop down menu using:
<select name="sitehome">
<?php
while($row = mysql_fetch_array( $result )) {
echo "<option value=\"".$row['linklocation']."\">".$row['linkname']." </option>";
}
?>
</select>
This seems to work fine. It loops through the fields 'linklocation' and 'linkname' - filling the drop down with the correct data from the database.
Because I haven't used the code:
selected="selected"
within that 'looped' drop down, naturally the first item in that list is displayed by default.
and obiously if I added the code - they would all be 'selected' - eventually making the last item in the list appear as the 'selected' option.
What I'm hoping to achieve is:
Find out what data is stored in 'sitehome' ($sitehome).
That data should always be ONE of the rows in the field 'linklocation' ($linklocation).
As the LOOP drop down is populating, when you come across the 'linklocation' that is equal to the data in 'sitehome' - echo the text 'selected="selected"'.
This should then make the default starting item in the drop down - the item that is currently the 'sitehome'.
Hope this makes sense!!!
Regards,