homepage Welcome to WebmasterWorld Guest from 54.163.72.86
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Populating Drop Down Boxes
Meat Curtian




msg:3583420
 5:59 pm on Feb 24, 2008 (gmt 0)

I have a number of drop down boxes that I want to populate dynamically when the page loads. What is the best approach to solve this problem?

 

henry0




msg:3583490
 9:31 pm on Feb 24, 2008 (gmt 0)

Here is a model

<select name=\"search_city\">";
$conn=db_connect();// your DB conn function or hard coded DB conn script
// note: $state was passed via a POST as such it calls for mysql_real_escape_string()
$query = "SELECT DISTINCT `city` FROM my_table WHERE `state` = '".mysql_real_escape_string($state)."' ORDER BY `city` ASC";
$result= mysql_query($query);
$num=mysql_num_rows($result);
$i=0;
// loop till all cities are gathered
// $i (for ittereation) will run untill $i <$num is no more correct
while ($i <$num)
{ // then build the options list
echo "<option>";
$search_city=mysql_result($result,$i,"city");
echo"$search_city";
$i++;
}
echo"</select>";

Meat Curtian




msg:3632492
 5:21 pm on Apr 22, 2008 (gmt 0)

Hi Henry,
Just getting back to this one....

What about a php scripts that contains the drop-down list. Each time the page loads, it calls the script to load the drop-down. This way, I do not have to populate a database....

Thanks...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved