homepage Welcome to WebmasterWorld Guest from 54.161.185.244
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Help with search
garwil



 
Msg#: 4355093 posted 6:20 am on Aug 25, 2011 (gmt 0)

Hi...

I have a search function on my index.php that searches for accommodation using Dependant Drop down select lists of Country, Province, Type of accommodation, dates from and to and this is sent to my search.php via url. This works fine but now I have added another dimension, being 'City' and cannot get it to work properly. Basically there are nine provinces each with associated cities hard coded into arrays. What is happening now is that although the correct search parameters are being sent via the url to search.php, all nine city select list values are being sent as per the below url. In addition the returned results are producing the last city from the last province in the list. e.g. I am searching for Province = KwaZulu-Natal, City = Ballito... 'Province=KwaZulu-Natal' is in my first array with associated cities and although I am selecting the correct city from that province and it is being sent to the url, results are being returned as Province =North West Province, City = Zeerust. being from the last array.
The Url being sent from the search form looks like this and has some other optional parameters included. I have the parameters I am having an issue with in BOLD

//localhost/lat/search.php?country=South+Africa&province=Kwazulu-Natal&city=Ballito&category=%25&fromday=00&frommonth=00&fromyear=0000&today=00&tomonth=00&toyear=0000&noguests=0&Submit=Go&city=%25&city=%25&city=%25&city=%25&city=%25&city=%25&city=%25&city=%25

My results look like this..
SEARCH SUMMARY
All establishments in Zeerust North West Province South Africa
1 Results Found
Somerset Guest House, Ballito
Apartments
Arrive as a guest, leave as a friend


I cannot find a way to stop all 9 provinces city select fields from being sent to the url..

My search box with select list looks like this... my code is too long for all of it to go here so have edited it down to give the most relevant...
This is my search code...

<td width="52%" valign="top"><form name="search" method="get" action="search.php">
<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td bgcolor="#F1F1F1" style="height: 20px; border: 1px solid #BBBBBB;"><div align="center"><b>Find Accommodation Here</b></div></td>
</tr>
<tr>
<td width="82%" style="border: 1px solid #BBBBBB;">
<table width="100%" border="0" align="right" cellpadding="0" cellspacing="2" bgcolor="#FAFAFA">
<tr>
<td>Country</td>
<td><select name="country">
<option value="%" show="none">Any Available Country</option>
<?php
$cities = dbGetRows("venues", "country != 'South Africa'");
$countcities = mysql_num_rows($cities);
if($countcities != 0) {
$othernote = "other";
} else {
$othernote = "none";
}

$selcountries = @mysql_query("SELECT DISTINCT country FROM venues where venues.published = '1' ");
while($venue = mysql_fetch_array($countries, MYSQL_ASSOC) ) {
echo "<option value=\"".$venue['country']."\" ".($_POST['country'] == $venue['country'] ? "selected" : "")."".($venue['country'] == 'South Africa' ? "show=\"provincesselect\"" : "show=\"$othernote\"").">".$venue['country']."</option>\n";
}
?>
</select></td>
</tr>
<?php
$region = Array("South Coast", "North Coast", "Durban Metro", "North Coast", "Zululand", "Drakensburg", "Elephant Coast", "Battlefields", "Midlands");
$provinces = Array("Kwazulu-Natal", "Eastern Cape", "Western Cape", "Orange Free State", "Gauteng", "Mpumalanga", "Northern Province", "Northern Cape", "North West Province");
$KwazuluNatal = Array("//removed all the array content as too long but the city search for '[b]Ballito[/b]' is in this array");
sort($KwazuluNatal);
$EasternCape = Array("//removed....");
sort($EasternCape);
$WesternCape = Array("//removed");
sort($WesternCape);
$OrangeFreeState = Array("//removed");
sort($OrangeFreeState);
$Gauteng = Array("//removed");
sort($Gauteng);
$Mpumalanga = Array("//removed");
sort($Mpumalanga);
$NorthernProvince = Array("removed");
sort($NorthernProvince);
$NorthernCape = Array("removed");
sort($NorthernCape);
$NorthWestProvince = Array("removed with the exception of, "[b]Zeerust[/b]", which is what is being returned on the search");
sort($NorthWestProvince);

if($countcities != 0) {
?>

<TR relation="other">
<td>City</td>
<td><input type="text" name="" value=""><br><font class="small">Leave blank for any city</font></td></tr>
<?php
}
?>

<TR relation="provincesselect">
<td>Province</td>
<td><select name="province">
<option value="%" show="none">Any Province</option>
<?php
$notallowed = "([-`~_+!&.(),'/\@#$%^*|}{:;\"\]\[?><]*)";

foreach($provinces AS $key => $province) {

$provincec = preg_replace($notallowed, "", $province);
$provincec = preg_replace('/\s/', '', $provincec);

echo "<option value=\"".$province."\"".($_POST['province'] == $province ? "selected" : "")." show=\"p-".$provincec."\">".$province."</option>\n";
}
?>
</select></td>
</tr>

<?php
echo "<TR relation=\"p-KwazuluNatal\">
<td>City</td>
<td><select name=\"city\">";
//echo "<option value=\"%\"show=\"none\">Any City</option>";
foreach($KwazuluNatal AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-EasternCape\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($EasternCape AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-WesternCape\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($WesternCape AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-OrangeFreeState\">
<td>City</td>
<td><select selected name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($OrangeFreeState AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-Gauteng\">
<td>City</td>
<td><select selected name=\"city\">";
echo "<option value=\"%\">Any City</option>";
foreach($Gauteng AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-Mpumalanga\">
<td>City</td>
<td><select selected name=\"city\">";
echo "<option value=\"%\">Any City</option>";
foreach($Mpumalanga AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-NorthernProvince\">
<td>City</td>
<td><select selected name=\"city\">";
echo "<option value=\"%\">Any City</option>";
foreach($NorthernProvince AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-NorthernCape\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($NorthernCape AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";

echo "<TR relation=\"p-NorthWestProvince\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($NorthWestProvince AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";



Am hoping someone here can point me in the right direction to stop all provinces cities benig posted as empty to the url

 

lostdreamer



 
Msg#: 4355093 posted 10:17 am on Aug 25, 2011 (gmt 0)

You seem to be forgetting to close all of the <select> boxes ;)


echo "<TR relation=\"p-NorthWestProvince\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($NorthWestProvince AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</td></tr>";


Should be


echo "<TR relation=\"p-NorthWestProvince\">
<td>City</td>
<td><select name=\"city\">";
echo "<option selected value=\"%\">Any City</option>";
foreach($NorthWestProvince AS $key => $city)
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
echo "</select></td></tr>";

garwil



 
Msg#: 4355093 posted 10:54 am on Aug 25, 2011 (gmt 0)

AAAAHHH! thanks lostdreamer... this is embarasing to say the least... how could I miss that...?

Have rectified that issue but no difference to the outcomes.. all cities still being posted and results still show Province and City from last array... been two days on this now and must have tried everything.. bar for the closing of the select tags that is :)

lostdreamer



 
Msg#: 4355093 posted 2:01 pm on Aug 25, 2011 (gmt 0)

I see that you also echo ALL of the TRs into the html.

This meens that all the select boxes (also the invisible ones) will be submitted with your form, that's why you only see the value of the last city.

If you use javascript to hide the TR's, also disable all the select boxes that you are hiding, this will stop them from submitting their values ;)

garwil



 
Msg#: 4355093 posted 9:44 pm on Aug 25, 2011 (gmt 0)

hi,

Can you elaborate on how I would hide select boxes with js please?

My code looks like this this now and am still having the issue which you point out is due to the hidden selects also submitting. I am not sure how to rectify the issue with javascript or any other method to be honest..i really appreciate your help tremendously as this driving me nuts now :)

<TR relation="p-KwazuluNatal">
<td>City</td>
<td><select name="city">;
<option value="%"show="none">Any City</option>
<?php
foreach($KwazuluNatal AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-EasternCape">
<td>City</td>
<td><select name="city">
<option selected value="%">Any City</option>
<?php
foreach($EasternCape AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-WesternCape">
<td>City</td>
<td><select name="city">
<option selected value="%">Any City</option>
<?php foreach($WesternCape AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-OrangeFreeState">
<td>City</td>
<td><select selected name="city">
<option selected value="%">Any City</option>
<?php foreach($OrangeFreeState AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-Gauteng">
<td>City</td>
<td><select selected name="city">
<option value="%">Any City</option>;
<?php foreach($Gauteng AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-Mpumalanga">
<td>City</td>
<td><select selected name="city">
<option value="%">Any City</option>
<?php foreach($Mpumalanga AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

<TR relation="p-NorthernProvince">
<td>City</td>
<td><select selected name="city">
<option value="%">Any City</option>
<?php foreach($NorthernProvince AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>


<TR relation="p-NorthernCape">
<td>City</td>
<td><select name="city">
<option selected value="%">Any City</option;
<?php foreach($NorthernCape AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>


<TR relation="p-NorthWestProvince">
<td>City</td>
<td><select name="city">
<option selected value="%">Any City</option>
<?php foreach($NorthWestProvince AS $key => $city){
echo "<option value=\"".$city."\"".($_POST['city'] == $city ? "selected" : "").">".$city."</option>\n";
}
?>
</select></td></tr>

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved