|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Using external files to populate a menu.
I am using three text files to populate three drop down menus (areas, towns and post codes) . Each option in the drop down corresponds to a field in a mysql database.
I would like to instigate a search based on the users selections, but am having a problem outputting the results. I have an option for 'all areas', 'all towns' and 'all post codes' and because these aren't fields in the database no results are returned... How do I write a results page that will display all areas from my database, or all towns etc.. if it is selected? Hope that makes sense. Here is my drop down menu code:- <form method=post action="srchtest1.php"> <select name="fieldOne"> <?php $myfile = file("areas.txt"); $options = sizeof($myfile); for ($i=0;$i<sizeof($myfile); $i++){ print "<OPTION>".$myfile[$i]."</OPTION>/n"; } ?> </select> <br> <select name="fieldTwo"> <?php $myfile1 = file("towns.txt"); $options = sizeof($myfile1); for ($i=0;$i<sizeof($myfile1); $i++){ print "<OPTION>".$myfile1[$i]."</OPTION>/n"; } ?> </select> <br> <select name="fieldThree"> <?php $myfile2 = file("zip.txt"); $options = sizeof($myfile2); for ($i=0;$i<sizeof($myfile2); $i++){ print "<OPTION>".$myfile2[$i]."</OPTION>/n"; } ?> </select> <br><br> <input name="Submit" type="Submit" value="Submit"> </form> and here is an example of one of the text files:- All Areas Devon North Devon North Cornwall Cheshire ---------------------------------------------------------------- An example of the script is here http://www.stevesims.com/jump3.php ------------------------------------------------------------------- |
|
#2
|
|||
|
|||
|
As far as I can see, the search in your database is an OR construction, probably something like:
Code:
SELECT * FROM table WHERE area=$area OR town=$town OR zipcode=$zipcode Why do you use a text file, to define the value to be searched for in a database? To me it seems to be more straight forward that you create your selection list on the content of the database and simply add the special value 'All ....' to the beginning. But that reminded me, you already did post such a solution (http://www.devarticles.com/forum/sh...=&threadid=2280). Are you still having difficulties with that result script? Regards, |
|
#3
|
|||
|
|||
|
The solution didn't ever work for 'all areas' or 'all towns' etc...
It works fine otherwise. The reason I am pulling text files in is that I want the user to be able to update these files through a browser, thus updating the menus...and avoiding any ftp uploading. So this is a slightly different scenario from the previous one, but I am seeking a solution that would probably work for both of my threads, as I still don't have one. |
|
#4
|
|||
|
|||
|
Steve,
Using text files is your decission. ![]() When 'all areas', 'all towns' and 'all zips' are submitted your SQL query should be staightforward and probably look like this: Code:
SELECT * FROM table Please (re)post your script, so I can have a look at it. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Using external files to populate a menu. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|