|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Results page continued..
I haven't had a solution to this yet, so I thought I woud re-post to freshen up the thread.
I have a php page that populates three drop down menus from a mysql database. But I don't know how to pass the selections through to a results page and am looking for help! My search page code 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 */ ?> <?php $query_Areas = "SELECT DISTINCT areas FROM houses ORDER by areas"; $Areas = mysql_query($query_Areas) or die(mysql_error()); $row_Areas = mysql_fetch_assoc($Areas); ?> <?php $query_Towns = "SELECT DISTINCT towns FROM houses ORDER by towns"; $Towns = mysql_query($query_Towns) or die(mysql_error()); $row_Towns = mysql_fetch_assoc($Towns); ?> <?php $query_zip = "SELECT DISTINCT zip FROM houses ORDER by zip"; $zip = mysql_query($query_zip) or die(mysql_error()); $row_zip = mysql_fetch_assoc($zip); ?> <body> <form name="form" method="post" action="menutest8b.php"> <p> <select name="field_1"> <option value="allareas">All areas</option> <?php do { ?> <option value="<?php echo $row_Areas['areas']?>"><?php echo $row_Areas['areas']?></option> <?php } while ($row_Areas = mysql_fetch_assoc($Areas)); ?> </select> </p> <p> <select name="field_2"> <option value="alltowns">All Towns</option> <?php do { ?> <option value="<?php echo $row_Towns['towns']?>"><?php echo $row_Towns['towns']?></option> <?php } while ($row_Towns = mysql_fetch_assoc($Towns)); ?> </select> <?php mysql_free_result($Towns); ?> </p> <p> <select name="field_3"> <option value="allzips">All Post Codes</option> <?php do { ?> <option value="<?php echo $row_zip['zip']?>"><?php echo $row_zip['zip']?></option> <?php } while ($row_zip = mysql_fetch_assoc($zip)); ?> </select> <?php mysql_free_result($zip); ?> </p> <p> <input type="submit" name="Submit" value="Submit" /> </p> </form> <?php mysql_free_result($Areas); ?> ---------------------------------------------------- |
|
#2
|
||||
|
||||
|
steve... ok first a couple of questions for you..
One, do you have register globals on or off? Two, when you click the submit button and it goes into the menutest8b.php , if you have register globals on, do you have the values of the posted items assigned to variables? for example: PHP Code:
or something to that effect? Let me know, I'll try to help you as much as I can.. if I dont know the answer right away let me do some research and I'll see what I can find out. -- Justin |
|
#3
|
|||
|
|||
|
Sorry I'm new to php and am unsure what you mean by register globals....sorry.
Below is the current code for a results page I have put together based on previous threads, but it doesn't work. You can view the live version of the drop down menu here, http://www.stevesims.com/menutest8.php I look forward to hearing from you.. ------------------------------------------------------------------------------- results page ------------------------------------------------------------------------------- <?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 */ $where =""; $areas = $_POST[field_1]; $towns = $_POST[field_2]; $zip = $_POST[field_3]; if (empty($areas) || empty($towns) || empty($zip)) { die ("You didn't pass parameters...\nSorry!"); } if ($areas != 'allareas') { $where .= (empty($where))?" ":" AND "; $where .= "areas = '$areas'"; } if ($towns != 'alltowns') { $where .= (empty($where))?" ":" AND "; $where .= "towns = '$towns'"; } if ($areas != 'allzips') { $where .= (empty($where))?" ":" AND "; $where .= "zip = '$zip'"; } $query = "SELECT * FROM houses"; if (!empty($where)) { $query .= " WHERE $where"; } ?> <table> <tr><td>Area</td><td>Town</td><td>Post Code</td></tr> <?php $res = mysql_query($query) or die(mysql_error()); while ($rw = mysql_fetch_array($res)) { ?> <tr><td><?=$rw["areas"] ?> </td><td><?=$rw["towns"] ?> </td><td><?=$rw["zip"] ?></td></tr> <?php } ?> </table> |
|
#4
|
||||
|
||||
|
It's quite alright.. sorry I did not clarify...
Open up your php.ini file and look for register globals = on if it's set to on, then turn it off and the $_POST[] and $_GET[] methods should work.. when I go home for lunch I will turn my webserver back on <had a power outage last night> and I'll see what else I can do to help you out for that.. but loook and see what your register globals is equal to.. and let me know on here |
|
#5
|
||||
|
||||
|
Ok.. I just looked at the life site and it seems to work if you only select the postal code.
What exactly are you trying to do? Pass the values through for something or what? I dont see anywhere in the code you posted where you have a form handler, what exactly are you going to do with the information you are posting to the file? are you putting it in a database? are you emailing it out? let me know so I know what to expect.. also, is the code you posted above the entire code you have in that file? if not, I need to know what code you use for the form handler.. not just bits and pieces.. Thanks! ![]() |
|
#6
|
||||
|
||||
|
Also, please post the code to the form file that is taking the results.. menutest8b.php
that way I know exactly what is going on in your environment ![]() it'll make things easier on me.. |
|
#7
|
|||
|
|||
|
Basically I'm new to php, so for a test I have set up a database table called houses. Within that table is data for the fields areas, towns and zip codes (post codes).
I would like to create a search page, with a drop down menu for each field. Then depending upon what the user selects I would like a results page to be shown. i.e If I select all areas, a town of London and a zip code, the results page would display the relevant results. You are right the post code does work for selections not for all post codes though. I would also like to link the id of the data in so I can make a link to the property in question. A good example of what I'm trying to can be seen here http://www.fpdsavills.co.uk/residen...quicksearch.asp basically the user enters a selection criteria and a results page with links to the relevant properties is then returned. I'm sure this must be a relatively simple process, but I just don't know how to do it! My code for the results page is currently like this:- ----------------------------------------------------------------------------- <?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 */ $where =""; $areas = $_POST[field_1]; $towns = $_POST[field_2]; $zip = $_POST[field_3]; if (empty($areas) || empty($towns) || empty($zip)) { die ("You didn't pass parameters...\nSorry!"); } if ($areas != 'allareas') { $where .= (empty($where))?" ":" AND "; $where .= "areas = '$areas'"; } if ($towns != 'alltowns') { $where .= (empty($where))?" ":" AND "; $where .= "towns = '$towns'"; } if ($areas != 'allzips') { $where .= (empty($where))?" ":" AND "; $where .= "zip = '$zip'"; } $query = "SELECT * FROM houses"; if (!empty($where)) { $query .= " WHERE $where"; } ?> <table> <tr><td>Area</td><td>Town</td><td>Post Code</td></tr> <?php $res = mysql_query($query) or die(mysql_error()); while ($rw = mysql_fetch_array($res)) { ?> <tr><td><?=$rw["areas"] ?> </td><td><?=$rw["towns"] ?> </td><td><?=$rw["zip"] ?></td></tr> <?php } ?> </table> --------------------------------------------------------------------- |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Results page continued.. |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|