Jump to content

search multiple fields using multiple form elements


bickyz

Recommended Posts

thank you very much barand, I have set the session at the top of the page, no errors now.

how do i now tag the session from index page to the sort-by drop down list in results page so that selecting items from the drop down will use the session.

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<?php
include 'db.inc.php';
?>
<?php
session_start();
$_SESSION['duration']='duration';
$_SESSION['datepicker']='datepicker';
$_SESSION['transport']='transport';
$_SESSION['activity']='activity';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Intranet Activities Search</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
<link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css" />
<script>
$(function() {
$("#datepicker").datepicker({dateFormat: 'yy-mm-dd'});
});
</script>
<style type="text/css" media="screen">
table {
	font-size: 14px;
}
</style>
</head>
<body>
<form id="form1" name="form1" method="post" action="listactivities.php">
  <table width="600" border="0" cellspacing="0" cellpadding="0">
        <tr>
      <td>Duration (days)</td>
      <td>
      <?php
      	$duration_options = '';
		for ($d=7; $d<=14; $d++) {
    	$sel = $d == $_SESSION['duration'] ? "selected='selected" : '';
    	$duration_options .= "<option $sel value='$d'> $d</option>";
		}
		?>
      <select name="duration" id="duration">
           <option value="">Any</option>
		   <?php echo $duration_options ?>
      </select></td>
    </tr>
      <tr>
        <td> </td>
        <td> </td>
      </tr>
      <tr>
      <td width="45%">Date (YYYY-MM-DD)</td>
      <td width="55%">
      <?php
	  	$datepicker_options['datepicker'] = 'datepicker';
		$_SESSION['datepicker'] = $datepicker_options['datepicker'];		
	  ?>
      <input name="datepicker" type="text" id="datepicker" />
      </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>Transportation</td>
      <td>
      <?php
     	$transport_options = '';
		$trans = array('included', 'excluded');
		foreach ($trans as $o) {
    	$sel = $o == $_SESSION['transport'] ? "selected='selected" : '';
    	$transport_options .= "<option $sel value='$o'> $o</option>";
		}
	 ?>
     <select name="transport" id="transport">
          <option selected="selected" value="0">Any</option>
		  <?php echo $transport_options ?>
      </select>  
       </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td colspan="2">
<?php
    $_SESSION['activity'] = (isset($_POST['activity'])) ? $_POST['activity'] : array();
    $query="SELECT * FROM inclusion ORDER BY incid";
    $test= mysql_query($query) or die(mysql_error());
    while(list($incid, $incdesc) = mysql_fetch_row($test)) {
        $chk = in_array($incid, $_SESSION['activity']) ? "checked='checked'" : '';
        echo "<input type=\"checkbox\" name=\"activity[]\" value=\"$incid\" $chk /> $incdesc <br>";
    }
?>
</td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td><input type="submit" name="searchbtn" id="searchbtn" value="Search" /></td>
      <td> </td>
    </tr>
  </table>
</form>
</body>
</html>
<?php mysql_free_result($test); ?>
  • Replies 50
  • Created
  • Last Reply

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.