Jump to content

Search box to drop down lists


jezh

Recommended Posts

Hi there, i have a php photo sharing website. I have the search feature with a text box a search button and a few radio buttons that you can search by date or title etc.

 

What i want to do is turn that text box into 3 drop down lists - day month year, then when the user clicks search it will search the title of the photo (which will be the date) but it will also take the 3 seperate drop down lists into one string.

 

Can anybody give me some advice with this? I have included the code which the site uses

 

this is the search.php page

 

<?

session_start();

 

$page_title      = ""; // PAGE TITLE FOR THIS PAGE - IF BLANK USE DEFAULT TITLE

$meta_keywords    = ""; // KEYWORD METATAGS FOR THIS PAGE - IF BLANK USE DEFAULT

$meta_description = ""; // DESCRIPTION METATAGS FOR THIS PAGE - IF BLANK USE DEFAULT

 

include( "database.php" );

include( "functions.php" );

include( "config_public.php" );

 

// VISITOR ID

if(!$_SESSION['visitor_id']){

session_register("visitor_id");

$_SESSION['visitor_id'] = random_gen(16,"");

}

 

//GET SEARCH DATA AND CHECK IT FOR BAD CHARACTERS

if($_POST['search'] != ""){

$my_search = $_POST['search'];

}

if($_GET['search'] != ""){

$my_search = $_GET['search'];

}

$replace_char = array("%20", "+", "\"", ">", "<", "'", "%22", "%3E");

$my_search = str_replace($replace_char, "", $my_search);

$my_search = trim($my_search);

 

//GET MATCH TYPE DATA FROM SEARCH BAR AND SAVE IT AS A SESSION

if($_POST['match_type'] != ""){

$match_type = $_POST['match_type'];

}

if($_GET['match_type'] != ""){

$match_type = $_GET['match_type'];

}

if(!$match_type){

$match_type = "all";

}

//UNSET ANY PREVIOUS NEXT BUTTON

unset($_SESSION['imagenav']);

//UNSET ANY SEARCH BAR DATA

unset($_SESSION['search_match_type']);

//GET ANY NEW CHANGES IN THE SEARCH BAR DATA

session_register("search_match_type");

$_SESSION['search_match_type'] = $match_type;

 

//UNSET ANY IMAGE VIEWING

unset($_SESSION['pub_gid']);

unset($_SESSION['pub_pid']);

 

?>

<html>

<head>

<script language=JavaScript src='./js/xns.js'></script>

<? print($head); ?>

<center>

        <table cellpadding="0" cellspacing="0"><tr><td valign="top">

<table cellpadding="0" cellspacing="0" width="765" class="main_table" style="border: 5px solid #<? echo $border_color; ?>;">

<? include("header.php"); ?>

<tr>

<td class="left_nav_header"><? echo $misc_photocat; ?></td>

<td></td>

<? include("search_bar.php"); ?>

</tr>

<tr>

<td rowspan="1" valign="top"><? include("i_gallery_nav.php"); ?></td>

<td background="images/col2_shadow.gif" valign="top"><img src="images/col2_white.gif"></td>

<td valign="top" height="18">

<table cellpadding="0" cellspacing="0" width="560" height="100%">

<tr>

<td colspan="3" height="5"></td>

</tr>

<tr>

<?php

$crumb = $search_gal_crumb_link;

include("crumbs.php");

?>

</tr>

<tr>

<td class="index_copy_area" colspan="3" height="4"></td>

</tr>

<tr>

<td colspan="3" valign="top" height="100%" class="homepage_line">

<table width="100%" border="0">

<tr>

<td height="6"></td>

</tr>

<tr>

<td class="gallery_copy">

<? copy_area(29,2); ?>

</td>

</tr>

<tr>

<td>

<?php

if(!empty($my_search)){

?>

<? include("i_search_photos.php"); ?>

<?php

}

?>

</td>

</tr>

<tr>

<td style="padding: 10px;"></td>

</tr>

</table>

</td>

</tr>

</table>

</td>

</tr>

<? include("footer.php"); ?>

</table>

        </td>

        <td valign="top">

<?php

if($pf_feed_status){

include('pf_feed.php');

}

?>

        </td>

        </tr></table>

</center>

</body>

</html>

<?

if($db != ""){

mysql_close($db);

}

?>

 

 

 

 

 

This is the search_bar.php file

 

<td class="search_bar">

<?PHP if($setting->search_onoff == 1){ ?>

<script language="javascript" type="text/javascript">

function validateForm(search)

{

 

if(""==document.forms.search.search.value)

{

alert("<? echo $search_alert; ?>");

return false;

}

 

}

</script>

<table width="100%">

<tr>

<td width="400" nowrap>

<div style="background-color: #E8E8E8; border: 1px solid #AFAFAF; padding: 3px;">

<form name="search" action="search.php" method="link" onSubmit="return validateForm(search);" style="margin: 0px; padding: 0px;">

<? echo $search_search; ?> <input type="textbox" name="search" class="search_box"> <input type="submit" value="<? echo $search_button; ?>" class="go_button">

<br />

<input type="radio" name="match_type" value="all" <? if($_SESSION['search_match_type'] == "all"){ echo "checked"; } ?>> <? echo $search_match_all; ?> | <input type="radio" name="match_type" value="any" <? if($_SESSION['search_match_type'] == "any"){ echo "checked"; } ?>> <? echo $search_match_any; ?><br><? if($setting->hide_id != 1){ ?><input type="radio" name="match_type" value="id" <? if($_SESSION['search_match_type'] == "id"){ echo "checked"; } ?>> <? echo $search_match_id; ?>   | <? } ?><input type="radio" name="match_type" value="exact" <? if($_SESSION['search_match_type'] == "exact"){ echo "checked"; } ?>> <? echo $search_match_exact; ?>

</form>

</div>

</td>

</tr>

</table>

<?PHP } ?>

  </td>

Link to comment
https://forums.phpfreaks.com/topic/160801-search-box-to-drop-down-lists/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.