hosted by liquidweb

Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Help populating 2 drop down lists from db

Forum Jump

Help populating 2 drop down lists from db

Reply Post New Thread In Programming Discussion Subscription
Send news tip View All Posts Thread Tools Search this Thread Display Modes
Old 12-20-2004, 11:32 AM
saghir69 saghir69 is offline
Web Hosting Master
Join Date: Jun 2004
Posts: 889

Help populating 2 drop down lists from db

Hi I need to make a form to submit some values to a db,

the form will have 2 drop down lists,

both will load from mysql

list 1 will be loaded on page load so thats ok

but list 2 needs to be loaded depending on the option selected in list1 .

can you please help me with that?

Sponsored Links
Old 12-20-2004, 01:39 PM
DynamicHost DynamicHost is offline
Junior Guru
Join Date: May 2003
Location: Halifax, Nova Scotia, Canada
Posts: 200
To do this with both drop downs on the same page you will need to populate Javascript arrays on the page load, it is much easier to do this on two separate pages if you can, if not though, it is possible, however if you have a large set of data to possibly populate the forms it will increase the loading times since all of the data will be printed inside the javascript that is sent out to the web browser.


Canadian Shared, Reseller and Dedicated Hosting

Old 12-20-2004, 02:34 PM
Angelo Angelo is offline
Web Hosting Master
Join Date: Mar 2004
Location: Los Angeles
Posts: 617

$query = mysql_query("SELECT field FROM table WHERE anything='$given'");
$result = mysql_fetch_array($query);


<input type="select" name="menu">
<option><?php echo $result[0]; ?></option>
<option><?php echo $result[1]; ?></option>
<option><?php echo $result[2]; ?></option>
Second option will need javascript to load something in somewhere, when "onChange".

Hosting Reviews

Sponsored Links
Old 12-20-2004, 03:09 PM
Vult-r Vult-r is offline
WHT Addict
Join Date: Nov 2003
Location: Netherlands
Posts: 149
A way to do this is to post the $value of the first combobox to itself (for example page.php?selection=bla).

On the page (re)load, check if the $seletion value exist, then execute a second query to fill a second combobox.

Then fcarsenal's code would look something like this..

<FORM name='selectionform'>
<SELECT name='subselection' onChange='window.location=document.selectionform.subselection.options[document.selectionform.subselection.selectedIndex].value'>
<OPTION SELECTED value='javascript:void(0)'>--Choose--
<OPTION value='page.php?selection=$result[0]'>$result[0]</OPTION>
<OPTION value='page.php?selection=$result[1]'>$result[1]</OPTION>
<OPTION value='page.php?selection=$result[2]'>$result[2]</OPTION>
</FORM >

Last edited by Vult-r; 12-20-2004 at 03:12 PM.
Old 12-20-2004, 05:02 PM
saghir69 saghir69 is offline
Web Hosting Master
Join Date: Jun 2004
Posts: 889
^ thanks guys for your response, but i've realised that this way will be too complicated for what i need it for, so instead, i'll be displaying a dynamic link on each page of the site (web directory)
the link will have right catagory and subcat within it, so the processor file will just display the names for the catagy the user is about to submit to. .

my question now is,

my site will be only one page(static) every other page will be dynamic.

i'm using something like this

in the php file i have this code

i know my synax is wrong here , i'm just typing rough
if isset(catid) && isset(subid)
echo 'the code for my form';
form action will be the same file
the question i have is how do i process the form inthis file and how would i display the confirmation on successful submition?

i don't want to use another page coz that will make it harder to manage stuff in the long run.

Old 12-20-2004, 05:25 PM
saghir69 saghir69 is offline
Web Hosting Master
Join Date: Jun 2004
Posts: 889
I'm actually working on it so i might sort it out, but in case someone replies thought i'll also mention that all the form validation will be done using javascript so alll i want from the php bit is to

1 display the form
2 on submit send the data and show the user a thankyou message.

Old 12-20-2004, 06:07 PM
Christopher Lee Christopher Lee is offline
WHT Addict
Join Date: Dec 2004
Location: Akron, Ohio
Posts: 115
A quick note: I wouldn't rely exclusively on JavaScript to do your form validation. Some very nasty things (read: SQL Injections) are trivial to do when this is your only form of validation.

Old 12-21-2004, 10:11 AM
saghir69 saghir69 is offline
Web Hosting Master
Join Date: Jun 2004
Posts: 889
hi thanks i've heard about addslashes but i don't know what to do with them. can you help?


Related posts from
Title Type Date Posted
Swarmify's New Approach to Content Delivery Uses Site Visitors to Accelerate Content Web Hosting News 2014-04-02 12:05:19
Cybercriminals Using Cloud Infrastructure to Launch Attacks: Annual FireHost Report Web Hosting News 2014-02-19 15:35:29
Video Demo: Cbeyond Hosted Microsoft Exchange Whir Tv 2013-10-05 06:20:04
Netcraft Continues to See a Drop in Responses for July 2012 Web Survey Web Hosting News 2012-07-03 14:35:26
Netcraft May Web Server Survey Sees First Drop in Responses in 22 Months Web Hosting News 2012-05-02 13:59:57

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Log in with your username and password

Forgot Password?
Web Hosting News:



Welcome to

Create your username to jump into the discussion! is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.

(4 digit year)

Already a member?