General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 26th, 2003, 06:02 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via AIM to steve55 Send a message via Yahoo to steve55
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);
?>

----------------------------------------------------

Reply With Quote
  #2  
Old January 26th, 2003, 09:42 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
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:
<?
    $submit 
$_POST['Submit'];
    if (
$submit) {
        
$allzips $_POST['allzips'];
        
$alltowns $_POST['alltowns'];
        
$allareas $_POST['allareas'];
    }
    echo 
"Allzips value: $allzips <br> \n";
    echo 
"Alltowns value: $alltowns <br>\n";
    echo 
"Allareas value: $allareas <br>\n";
?>


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

Reply With Quote
  #3  
Old January 26th, 2003, 11:41 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via AIM to steve55 Send a message via Yahoo to steve55
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>

Reply With Quote
  #4  
Old January 26th, 2003, 11:47 AM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
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

Reply With Quote
  #5  
Old January 26th, 2003, 12:12 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
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!

Reply With Quote
  #6  
Old January 26th, 2003, 12:14 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 653 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
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..

Reply With Quote
  #7  
Old January 27th, 2003, 04:19 AM
steve55 steve55 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: UK
Posts: 44 steve55 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via AIM to steve55 Send a message via Yahoo to steve55
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>

---------------------------------------------------------------------

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Results page continued..


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT