views:

63

answers:

1

Would it be possible to run a MySQL query pulling the names of locations from a table, inserting them into a dropdown menu and then automatically generating a URL for each one e.g. blablabla.bla/index.php?location=blablabla every time the page loads?

Any help is appreciated.

+3  A: 

Sure, you would just run the query, parse the results through a loop in which you would build your links from the returned values -- concatenating the result text to the other portion of your links.

<select name='locations'>
<?php
while ($row = mysql_fetch_assoc($result))
{
    echo "<option value='".$row['location']."'>".$row['location']."</option>";
}
?>
</select>
byte
Ah, ok. That helps a lot, I'm still new to PHP and SQL so I will probably have more questions in the future lol. Thanks :)
Shoaulin
+1 But be sure to escape output with htmentities(). See http://en.wikipedia.org/wiki/Cross-site_scripting
Bill Karwin