473,324 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Load database values to drop down

250 100+
i have two drop down boxes and when user select District from 1st drop down box , the cityis in that district should load to the second drop down.
My code is below. But it is not working. Please tell me what is incorrect with it.

[PHP] <tr>
<td width="111">
<form action="test.php" method="post" name="test" >
<select name="District" class="defaultBlackText" onchange="this.form.submit();">
<option <?php if ($_POST['District'] == 'G1') print 'selected '; ?> value="G1">G1</option>
<option <?php if ($_POST['District'] == 'G2') print 'selected '; ?> value="G2">G2</option>
<option <?php if ($_POST['District'] == 'G3') print 'selected '; ?> value="G3">Kurunegala</option>
</select>
</form>
</td>
<td width="15">&nbsp;</td>
<td width="145">
<form action="test.php" method="post" name="testl">
<select name="city" onchange="this.form.submit();">
<option value="Select">Select</option>
</select>
</form>
</td>
<td width="138"><?php if (isset($_POST['District']))
{
echo $_POST['District'];
$District=$_POST['District'];
$q="SELECT * FROM xxx WHERE District='".$District."' ";
$result=mysql_query($q) or die ("Could not execute query: $q.".mysql_error());
while($row=mysql_fetch_array($result)){
foreach( $row AS $key => $val ){
$key = stripslashes( $val );
}

}
}

?> </td>
<td width="158">
</td>
<td width="12">&nbsp;</td>
<td width="190"></td>
<td>&nbsp;</td>
</tr>[/PHP]
Mar 26 '08 #1
3 2650
ronverdonk
4,258 Expert 4TB
No wonder it is not working and, by the way, you did not show all your code.

Secondly the only 2nd drop down box on this form is this one[php] <select name="city" onchange="this.form.submit();">
<option value="Select">Select</option>
</select>[/php]but you don't fill it anywhere, as you should between the <option> and the </select>. I cannot understand the meaning of the filling of a $key variable in the foreach loop. What is its purpose?

Ronald
Mar 26 '08 #2
ghjk
250 100+
No wonder it is not working and, by the way, you did not show all your code.

Secondly the only 2nd drop down box on this form is this one[php] <select name="city" onchange="this.form.submit();">
<option value="Select">Select</option>
</select>[/php]but you don't fill it anywhere, as you should between the <option> and the </select>. I cannot understand the meaning of the filling of a $key variable in the foreach loop. What is its purpose?

Ronald

I want to take database value using it and want to load database values to second dropdown box.
Mar 27 '08 #3
ronverdonk
4,258 Expert 4TB
I want to take database value using it and want to load database values to second dropdown box.
Yes, I understood that already. But, as you said in your first post, you want to know what is wrong with it.

I gave you an answer but you don't acknowledge that answer, you just repeat your original question. Look at my post and see what is wrong.

Ronald
Mar 27 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: SirPoonga | last post by:
I think I'd have to do a combination of ASP and javascript to do this. What I want to do fill the first drop down box with values from a database query. Then based off that selection fill in the...
2
by: Chris Becker | last post by:
This is my attempt to rephrase a question I asked earlier that got no response. I suspect it was my poor/unplanned wording. Here is another attempt: I have a form with some drop down lists. I...
9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
2
by: macyp | last post by:
I have to pass values from one aspx page to another. The controls I have in the first page are: a textbox, 3 drop down lists, and 2 check boxes, and a submit button. It is a search page, and the...
2
by: kavi | last post by:
Can anyone send me the script for supplying the values in drop down list of the web page? I have couple of drop down list controls in my web page. I need to supply multiple values for each...
2
by: Jim Gregg | last post by:
Hello all, I am faced with some logic that I am unsure how to handle. Imagine that I am running a WMI query and I am outputting the data into a dynamically created ASP table control. Here is my...
1
by: inbamca | last post by:
Hi, Functionality is like when pressing 'CTRL+click' on drop down list in the main jsp page, a popup window appears with a list box contains all the values of the drop down clicked on the main page....
4
by: gihope | last post by:
Hi, I have an ASP.NET 2.0 C# issue that has been troubling me for some time, and if someone could shed some light on this I would appreciate it. This seems to be a commonly themed question,...
1
by: JohnMV | last post by:
Hi, I have 3 related drop down menus all of which need to be populated from database.In the first list i populated the values from the database. But i have trouble to proceed further. The...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.