|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
I have just got a drop down menu working - populated by fields in my mysql dbase and have a resulting results page working as well! (I'm new to this)
But I need to add in a ALL option in my drop downs. Currently the choice is <select>usa</select> <select>uk</select> <select>australia</select> So my results have to contain one of the above options - I don't know how to add in an option for ALL and how to code it... My current script for the drop down is as follows:- <?php include "config.php"; $db = mysql_connect ($Host, $User, $Password); mysql_select_db ($DBName) or die ("Cannot connect to database"); /* We have now connected, unless you got an error message */ $SQL = "SELECT id, areas, towns, zip FROM houses"; $myResult = mysql_query($SQL, $db); while(list($id, $areas, $towns, $zip) = mysql_fetch_array($myResult)) { $menuOne .= "<option value=\"$areas\">$areas</option>\r"; $menuTwo .= "<option value=\"$towns\">$towns</option>\r"; $menuThree .= "<option value=\"$zip\">$zip</option>\r"; $menuFour .= "<option value=\"$id\">$id</option>\r"; } mysql_close($db); echo "<form action=\"srchtest1.php\" method=\"POST\">\r"; echo "<select name=\"fieldOne\">$menuOne</select>\r"; echo "<select name=\"fieldTwo\">$menuTwo</select>\r"; echo "<select name=\"fieldThree\">$menuThree</select>\r"; echo "<input type=\"Submit\" name=\"Submit\" value=\"Submit\">\r"; "<INPUT TYPE=\"HIDDEN\" NAME=\"id\" value=$menuFour>\r"; echo "</form>\r"; ?> Any help would be appreciated. Thanks |
|
#2
|
|||
|
|||
|
steve,
Do you mean you want to be able to select all the countries in the list? Firstly you will need to add the following code to the select box multiple size="5" then you will need to run some javascript that will go though the array of option elements and select each one. |
|
#3
|
|||
|
|||
|
Basically if the user leaves drop down box it will 'select' all from that particular menu, as you correctly point out.
However I still don't have a clue how to do this...! |
|
#4
|
|||
|
|||
|
Steve,
Perhaps I'm totally off-base here (wouldn't surprise me ), but why don't you check to see if a value is passed from the drop down box? If a value is not passed, you use a default value - which is every value in that box.Or, you might have an "all" option in the box, and check for this value with the script the form is pointed to - if it exists, you simply grab all the values from MySQL again and use them. Otherwise, you use the value the user passed. Just a thought ![]() Peace, Jeb. |
|
#5
|
|||
|
|||
|
This is my results page - any ideas?
<? include "config.php"; if ($Submit) // perform search only if a string was entered. { $db = mysql_connect ($Host, $User, $Password); mysql_select_db ($DBName) or die ("Cannot connect to database"); $srch="%".$Submit."%"; $query = "select * from houses WHERE areas LIKE '$fieldOne' || towns LIKE '$fieldTwo' || zip LIKE '$fieldThree' "; $result = mysql_db_query("stevesims", $query); if ($result) { echo "Here are the results:<br><br>"; echo "<TABLE border = '1' cellspacing = '0' cellpadding ='0' width = '90%' align='center'><tr> <td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">URL</font></td> <td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Area</font></td> <td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Town</font></td> <td align=center bgcolor=#0099ff><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">Post Code</font></td> </tr>"; while ($r = mysql_fetch_array($result)) { // Begin while $areas = $r["areas"]; $towns = $r["towns"]; $zip = $r["zip"]; $id = $r["id"]; echo "<tr> <td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\"><A HREF=\"http://www.stevesims.com/dummy/view2c.php?id=$id\"><b>View Property</b></A></font></td> <td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$areas</font></td> <td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$towns</font></td> <td><font size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">$zip</font></td></tr> "; } // end while echo "</table>"; } else { echo "problems...."; } } else { echo "Search string is empty. <br> Go back and type a string to search"; } ?> |
|
#6
|
|||
|
|||
|
PHP Code:
Using wildcards we could build the query as so. On your select menus, have the default value (Select One) set to '0'. So, if $_POST['a'] comes into the script as '0', it is considered empty - so we can bind $a to '%' or wildcard matching everything.
__________________
~ Joe Penn We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set? Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you. |
|
#7
|
|||
|
|||
|
Thanks, but I'm still having problems, probably because I'm new to this rather than anything else.
I have got the drop down menus & results page working, but currently it pulls everything out the database and puts it into the drop downs, like so <select>london</select> <select>New York</select> <select>Toronto</select> etc..... So the user HAS TO select a city. - I would like to change it to this, <select>CHOOSE A CITY</select> <select>london</select> <select>New York</select> <select>Toronto</select> etc... ..SO if the user leaves the drop down as CHOOSE CITY, the results page displays ALL CITIES as opposed to say just london, or just New York, or just Toronto. I just don't know how to do it.. |
|
#8
|
|||
|
|||
|
PHP Code:
Ok - lets break the above function down: Line 1: The opening tags of the select menu where $_nam is the name you are identifying the menu as (fed to the function on the function call). Line 2: The first option in the menu (and the defualt). No value is givin to this. Line 3: Your query to grab the list of cities from your DB. Each city in your DB needs an identifying id. Line 4: The start of the data loop from your DB. Line 5: The actual option values and corresponding names that will be in the menu. Line 6: Close of the loop. Line 7: The closing HTML tag of the select menu. Line 8: Returns the HTML block into your current script namespace. ---------------------------------------- Now, to call the function and build the menu, place the code below in your page where you want the menu to appear -> PHP Code:
Now, make sure that you also include the function at the top of your page. The initial select option is left blank so if the user does'nt choose a city, the blank entry would mean your wildcard search. |
|
#9
|
|||
|
|||
|
Thanks for your patience and help.
|
|
#10
|
|||
|
|||
|
That works thank you - but I still need to add it a form action and button to proceed to the results page...
Also is there any way of telling the script to only list duplicate entries in the menu once.. The menu is for a dummy property database I have set up to teach myself php etc.... the menu currently looks like this, <select>Choose a City</select> <select>New York</select> <select>New York</select> <select>London</select> <select>Toronto</select> <select>New York</select> This is because I have entered in three properties in the city of New York, obviously the more I entries I add for New York the more times it will appear in the menu... |
|
#11
|
|||
|
|||
|
Ok, the form action and button is in your HTML, so no need to go over that. To get rid if the duplicate entries in your menu, adjust your query to this ->
PHP Code:
The DISTINCT tells mysql to return non-duplicate entries or only one entry for each multiple entry.... |
|
#12
|
|||
|
|||
|
Thank you, for your help - much appreciated and definitely a weight off my mind.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Doh! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|