steelbut Posted July 15, 2010 Share Posted July 15, 2010 Hopefully someone can help, I'm new to PHP and it seems like a large knowledge base here. I have a web site where the user would choose there country and the info in added to the url to a submit page. And example would be http://www.peb-buildings.com/quote.php?building_country_id=Angola I need Angola to be inserted as selected as the first option if a country is present. Then if empty the rest of the code pulls up the option of the US then you pick a state and so on. The code is below. Thanks a head of time! Larry <td class=field-text><select name="building_country_id"> <?php $query = "select * from countries order by country_name"; $result = mysql_query($query); $sqlError = mysql_error(); if (!empty($sqlError)) { logError($sqlError,$query,__LINE__); } while ($row = mysql_fetch_array($result)) { ?> <option value="<?php echo $row['country_id'] ?>"<?php echo ($row['country_id'] == 1000 ? " selected" : "") ?>><?php echo $row['country_name'] ?></option> <?php } ?> </select></td> Quote Link to comment Share on other sites More sharing options...
dbk Posted July 15, 2010 Share Posted July 15, 2010 Well, you can catch the country_id with the $_GET['country_id'] and put it into a variable. Then you can use it in the query to get the wanted data! Hope this is what your asking for! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.