473,385 Members | 1,907 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,385 software developers and data experts.

auto populate multiple list menu based on mysql

25
hello..
i have a question about how to make dependent list menu based on mysql?

actually, i already found some code that helped me a lot but there has a problem that is i want to change 'get' method to 'post' method.
can u all help me or guide me how to change this code.

thank you

Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $state = $county = null; //declare vars 
  3.  
  4. $conn = mysql_connect("localhost", "root", "12345"); 
  5. $db = mysql_select_db('test',$conn); 
  6.  
  7. if(isset($_GET["state"]) && is_numeric($_GET["state"])) 
  8. $state = $_GET["state"]; 
  9.  
  10. if(isset($_GET["county"]) && is_numeric($_GET["county"])) 
  11. $county = $_GET["county"]; 
  12. ?> 
  13.  
  14. <script language="JavaScript"> 
  15. function autoSubmit() 
  16. var formObject = document.forms['theForm']; 
  17. formObject.submit(); 
  18. </script> 
  19.  
  20. <form name="theForm" method="get"> 
  21.  
  22.  
  23. <select name="state" onChange="autoSubmit();"> 
  24. <option value="state">Select State</option> 
  25. <?php 
  26. $sql = "SELECT * FROM cat_state"; 
  27. $countries = mysql_query($sql,$conn); 
  28. while($row = mysql_fetch_array($countries)) 
  29. echo ("<option value=\"$row[state_id]\" " . ($state == $row["state_id"]? " selected" : "") . ">$row[state]</option>"); 
  30. ?> 
  31. </select> 
  32.  
  33. <?php 
  34. if($state!= null && is_numeric($state)) 
  35. ?> 
  36.  
  37. <select name="county" onChange="autoSubmit();"> 
  38. <option value="county">Select County</option> 
  39.  
  40. <?php 
  41. $sql = "SELECT * FROM cat_county WHERE state_id = $state "; 
  42. $countys = mysql_query($sql,$conn); 
  43. while($row = mysql_fetch_array($countys)) 
  44. echo ("<option value=\"$row[county_id]\" " . ($county == $row["county_id"]? " selected" : "") . ">$row[county]</option>"); 
  45. ?> 
  46. </select> 
  47. <?php 
  48. ?> 
  49.  
  50.  
Jun 18 '10 #1
1 3051
code green
1,726 Expert 1GB
Just edit $_GET to $_POST and change web form "method = post".
But remember $_GET can also read URL variables
Jun 18 '10 #2

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

Similar topics

1
by: 234 | last post by:
Please help. I'm first start to use javascript but I don't know how to develop the captioned. e.g. <select name="select" onChange="change(this.options.selectedIndex)"> <option...
2
by: Nick | last post by:
Is it possible through css to make an element in a multiple list menu unselectable. Im organizing my list by using titles... +-------------+ | CATEGORY 1 | | option 1 | | option 2 | | ...
5
by: Derek | last post by:
Let's say I have a dynamic list/menu, which gets its values from a database table, for example a list of contact people where the value is an ID number and the label is the name. However, if the...
6
by: Joe | last post by:
I have 2 multi-list boxes, 1 displays course categories based on a table called CATEGORIES. This table has 2 fields CATEGORY_ID, CATEGORY_NAME The other multi-list box displays courses based on...
2
by: webfreak | last post by:
hello am a relative newbie to php. am using dreamweaver,php/mysql. i want to populate a mysql field using a multiple selection list menu. i have been to countless forums and so far nothing. can...
5
by: joshua.nicholes | last post by:
I have an access database that consists of two tables.A data collection table and a species list table. The data collection table has about 1500 records in it and the species list has about 600....
3
by: joseph.mccastlain | last post by:
Hello All, I am a new user to Access. I am currently designing a database consisting of four tables for multiple users. Rather than bore you with the goals and such, here is what I am...
1
by: amel86 | last post by:
Hello, I have a problem. I need to do multiple list menu which is populate each other when selected. The problem is my code run perfect on my localhost server but when i upload to the server the...
1
by: yenom red | last post by:
i have a drop down list tied to a database called location. what i hope to achieve is once a location is selected, my other drop down list will auto-populate a list of department in that location....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.