PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 13th, 1999, 08:58 PM
juspin
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
Does anybody know how to make drop down boxes stay selected after doing a search?

I have a keyword search set up on my regional search engine. The search function not only uses keywords to search, it also uses 2 drop down boxes. vFor instance let's say you were looking for "Cheap" "real estate" in "Fort Collins." First, you would click the category drop down menu "Real Estate," then you would click the city drop down menu "Fort Collins" and finally enter the keyword "Cheap" into the search field.

The search results page works fine, however it would cool if the drop down boxes stayed selected (i.e. Real Estate, Fort Collins, and not to push it, but it would be really cool if the keywords stayed in the search field too).

You can see it in action if you go here: http://johnny.ncolorado.com/youwontguess.php3.

Here's the code:

<?
$sql = " SELECT * FROM cities ORDER BY city";
$city_result = mysql("nco", $sql);
$city_num = mysql_numrows($city_result);
?>

<?
$sql = " SELECT categories.*, categoryparent.category_id";
$sql .= " FROM categories,categoryparent";
$sql .= " WHERE categories.category_id=categoryparent.category_id";
$sql .= " && categoryparent.parent_id=0";
$sql .= " ORDER BY category";
$categories_result = mysql("nco", $sql);
$categories_num = mysql_numrows($categories_result);
$catpercolumn = round($categories_num / 2);
?>

<FORM ACTION="nc_results.php3" ENCTYPE="x-www-form-encoded" METHOD="POST">
<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="600" >
<TR VALIGN=TOP>
<TD ALIGN=RIGHT WIDTH="15"><IMG SRC="images/ncsearchleftround.gif" HEIGHT=55 WIDTH=13></TD>
<TD WIDTH="570" BGCOLOR="#CC9900">
<CENTER><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0 WIDTH="100%" >
<TR VALIGN=TOP>
<TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>&nbsp;
Choose A City</FONT></FONT></FONT></B></TD>

<TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>Pick
A Category</FONT></FONT></FONT></B></TD>

<TD><B><FONT FACE="Arial,Helvetica"><FONT COLOR="#5F4B7C"><FONT SIZE=-1>Enter
Keywords</FONT></FONT></FONT></B></TD>

<TD><IMG SRC="images/dell2.gif" HEIGHT=13 WIDTH=101></TD>
</TR>

<TR ALIGN=LEFT VALIGN=TOP>

<!--Start City Drop Down List-->
<TD>&nbsp;<SELECT name = "city_id"><OPTION value="all">All Cities
<? $i = 0; while ($i < $city_num) { ?>
<OPTION value="<? echo mysql_result($city_result, $i, "city_id"); ?>"><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($city_result, $i, "city"); ?>
<? $i++; } ?>
</SELECT>&nbsp;</FONT></FONT></FONT></TD>
<!--End City Drop Down List-->


<!--Start Category Drop Down List-->
<TD><SELECT name="category_id"><OPTION value="all">All Categories
<? $i = 0; while ($i < $categories_num) { ?>
<OPTION value="<? echo mysql_result($categories_result, $i, "category_id"); ?>"><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($categories_result, $i, "category"); ?>
<? $i++; } ?>
</SELECT>&nbsp;</FONT></FONT></FONT></TD>
<!--End Category Drop Down List-->

<TD><INPUT type="text" Name="keywordsearch" size="22">
</TD>

<TD>&nbsp;<INPUT TYPE="submit" NAME="submit" VALUE="Search"></TD>
</TR>
</TABLE></CENTER>
</TD>

<TD ALIGN=LEFT WIDTH="15"><IMG SRC="images/ncsearchrightround.gif" HEIGHT=55 WIDTH=13></TD>
</TR>

<TR ALIGN=RIGHT>
<TD></TD>

<TD><FONT FACE="Arial,Helvetica"><FONT SIZE=-1><A HREF="about.php3">What
Is This?</A> |&nbsp;</FONT> <FONT SIZE=-1><A HREF="addsite.php3">Add Your
Site</A></FONT></FONT> |&nbsp;<FONT FACE="Arial,Helvetica"><FONT SIZE=-1>
<A HREF="feedback.php3">Feedback</A> | <A HREF="faq.php3">Frequently Asked
Questions</A> | <A HREF="faq.php3">Help</A> | <A HREF="searchtips.php3">Search
Tips</A></FONT></FONT></TD>

<TD></TD>
</TR>
</TABLE>
</CENTER>
</FORM>

Reply With Quote
  #2  
Old December 14th, 1999, 08:25 AM
PAV
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
In your case I would use javascript to navigate and to pass the option-value as variable attached to the URL to a reload of the menu and set the selected option.
E.g. <FORM onSubmit="changePages(this.form)">; in your javascript function you then define:
changePages(form) {
parent.frame1name.location.href = nc_results.php3; parent.frame2name.location.href = menu.php3?city_id=form.select1name.options[form.select1name.selectedIndex].value&category_id=form.select2name.options[form.select2name.selec tedIndex].value;
}
In your menu.php3 file you script:
<? $i=0; while (....): ?>
if($row["city_id"]== $city_id) { $selected=" SELECTED"; }
else {$selected = ""; }
<OPTION value="<? echo mysql_result($city_result, $i, "city_id"); ?>"<? echo $selected; ?>><FONT FACE="Arial,Helvetica"><FONT COLOR="#000000"><FONT SIZE=-1><? echo mysql_result($city_result, $i, "city"); ?>
<? $i++; endwhile ?>

Do the same for category_id.

Hope it gets you where you want to go!

[This message has been edited by PAV (edited 12-14-99).]

[This message has been edited by PAV (edited 12-14-99).]

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Setting up a search - Need help.

Developer Shed Advertisers and Affiliates



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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap