Jump to content

Recommended Posts

  • Replies 50
  • Created
  • Last Reply

Top Posters In This Topic

Hi barand, thank you very much. I have managed to get results side by side by using follwing changes, could you please check if I my code looks good.

<?php
    $where = array();
    $whereclause = '';
    
    if (!empty($_POST['duration'])) {
        $val = intval($_POST['duration']);
        $where[] = "(acdur = $val)";
    }
    
    if (!empty($_POST['transport'])) {
        $val = mysql_real_escape_string($_POST['transport']);
        $where[] = "(actransp = '$val')";
    }
	
	    if (!empty($_POST['datepicker'])) {
        $val = mysql_real_escape_string($_POST['datepicker']);
        $where[] = "(acdate = '$val')";
    }
    
   // assuming you change you checkbox names
    if (isset($_POST['activity'])) {
        $val = join(",", array_map('intval', $_POST['activity']));
        $where[] = "(incl_activity.incid IN ($val))";
    }
	    
    if (count($where)) $whereclause = "WHERE " . join(' AND ', $where);
    
    // and you search query is
    /*$query = "SELECT * 
	FROM activities, incl_activity, inclusion  
	JOIN incid
	$whereclause";*/
	
	/*
	$query = "SELECT * FROM activities
			JOIN incl_activity on activities.acid = incl_activity.acid
			JOIN inclusion on incl_activity.incid = inclusion.incid
			JOIN teamleader on activities.tlid2 = teamleader.tlid
			$whereclause";*/
			
$query = "SELECT activities.*, teamleader.tlname, GROUP_CONCAT(incdesc SEPARATOR ', ') as Includes  
FROM activities
JOIN incl_activity on activities.acid = incl_activity.acid
JOIN inclusion on incl_activity.incid = inclusion.incid
JOIN teamleader on activities.tlid2 = teamleader.tlid
$whereclause
GROUP BY activities.acid
ORDER BY teamleader.tlname ASC";
			
			
	
			
	//echo $query;
	$test= mysql_query($query) or die(mysql_error());
	
	if(mysql_num_rows($test))
	{
	$i=1;
	echo '<table><tr>';
	
	while($row = mysql_fetch_assoc($test)){
	
	$actitle=$row["actitle"];
	$tlname=$row["tlname"];
	$acdate=$row["acdate"];
	$acdur=$row["acdur"];
	$accost=$row["accost"];
	$incdesc=$row["Includes"];
	$actransp=$row["actransp"];
	
	echo '<td>'."$actitle <br> $tlname <br> $acdate <br> $acdur <br> $accost <br> $incdesc <br> $actransp <br><br>".'</td>';
	        if($i % 4 == 0)
                echo '</tr><tr>';
       $i++;
}
echo '</tr></table>';
      }
else
{
     echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>';
}

?>

try

 

    if(mysql_num_rows($test))
    {
        $i=0;    
        while($row = mysql_fetch_assoc($test)){
        
            $actitle=$row["actitle"];
            $tlname=$row["tlname"];
            $acdate=$row["acdate"];
            $acdur=$row["acdur"];
            $accost=$row["accost"];
            $incdesc=$row["Includes"];
            $actransp=$row["actransp"];
            
            echo "<div style='width:250px; padding:10px; float:left;'>
                $actitle <br> $tlname <br> $acdate <br> $acdur <br> $accost <br> $incdesc <br> $actransp
                </div>";
            $i++;            
            if($i % 3 == 0) echo "<div style='clear:both'></div>\n";
            
        }
        if ($i%3) echo "<div style='clear:both'></div>\n";
    }

Hi Barand, thank you very much for your help.

Can you please give me an idea on how the code will be if i want to implement a drop down list to sort the results. I have created a form on the top of this results page with following code

<form name="form1" method="post" action="">
<select name="sort" id="sort">
      	<option selected="selected" value="0">Sorty by</option>
        <option value="costlow">Price Ascending</option>
        <option value="costhigh">Price Descending</option>
        <option value="durlow">Duration Ascending</option>
        <option value="durhigh">Duration Descending</option>
        <option value="nameasc">Teamleader Name ASC</option>
        <option value="namedesc">Teamleader Name DESC</option>
        <option value="acdate">Date Ascending</option>
	<option value="acdate">Date Descending</option>
      </select>
</form>

Something like this, maybe

 

switch ($_POST['sort']) {
    case '0':     $orderby = '';  break;
    case 'costlow': $orderby = " ORDER BY acprice"; break;
    case 'costhigh': $orderby = " ORDER BY acprice DESC"; break;
    // etc
}

$query .= $orderby;  // add order by clause to the query

Note: your date sort options both have same value!

Edited by Barand

Hi barand, thank you very much for your help.

When I search, it does give me a results but it also throws me following error:

 

Notice: Undefined index: sortby in /htdocs/listactivities.php on line 28
Notice: Undefined variable: orderby in /htdocs/listactivities.php on line 78

 

Line 28 is switch ($_POST['sortby']) {

Line 78 is $orderby";

 

While on the results page if I select anything from the sort by drop down list, the results page displays everything clearing out the search results, sort by does works though.

 

demo http://bickyz.byethost13.com/

<form name="form1" method="post" action="">
<select name="sortby" id="sortby" onChange="this.form.submit()">
      	<option selected="selected" value="0">Sorty by</option>
        <option value="costasc">Price Ascending</option>
        <option value="costdesc">Price Descending</option>
        <option value="durasc">Duration Ascending</option>
        <option value="durdesc">Duration Descending</option>
        <option value="nameasc">Teamleader Name ASC</option>
        <option value="namedesc">Teamleader Name DESC</option>
        <option value="dateasc">Date Ascending</option>
		<option value="datedesc">Date Descending</option>
      </select>
</form>
<?php
switch ($_POST['sortby']) {
    case '0':     $orderby = '';  break;
    case 'costasc': $orderby = " ORDER BY accost ASC"; break;
    case 'costdesc': $orderby = " ORDER BY accost DESC"; break;
	case 'durasc': $orderby = " ORDER BY acdur ASC"; break;
	case 'durdesc': $orderby = " ORDER BY acdur DESC"; break;
	case 'nameasc': $orderby = " ORDER BY tlname ASC"; break;
	case 'namedesc': $orderby = " ORDER BY tlname DESC"; break;
	case 'dateasc': $orderby = " ORDER BY acdate ASC"; break;
	case 'datedesc': $orderby = " ORDER BY acdate DESC"; break;
    // etc
}

//$query .= $orderby;  // add order by clause to the query
?>
<p></p><p></p>
<?php
    $where = array();
    $whereclause = '';
    
    if (!empty($_POST['duration'])) {
        $val = intval($_POST['duration']);
        $where[] = "(acdur = $val)";
    }
    
    if (!empty($_POST['transport'])) {
        $val = mysql_real_escape_string($_POST['transport']);
        $where[] = "(actransp = '$val')";
    }
	
	    if (!empty($_POST['datepicker'])) {
        $val = mysql_real_escape_string($_POST['datepicker']);
        $where[] = "(acdate = '$val')";
    }
    
   // assuming you change you checkbox names
    if (isset($_POST['activity'])) {
        $val = join(",", array_map('intval', $_POST['activity']));
        $where[] = "(incl_activity.incid IN ($val))";
    }
	    
    if (count($where)) $whereclause = "WHERE " . join(' AND ', $where);
			
$query = "SELECT activities.*, teamleader.tlname, GROUP_CONCAT(incdesc SEPARATOR ', ') as Includes  
FROM activities
JOIN incl_activity on activities.acid = incl_activity.acid
JOIN inclusion on incl_activity.incid = inclusion.incid
JOIN teamleader on activities.tlid2 = teamleader.tlid
$whereclause
GROUP BY activities.acid
$orderby";

//ORDER BY teamleader.tlname ASC";
			
	//echo $query;
	$test= mysql_query($query) or die(mysql_error());
	
	    if(mysql_num_rows($test))
    {
        $i=0;    
        while($row = mysql_fetch_assoc($test)){
        
            $actitle=$row["actitle"];
            $tlname=$row["tlname"];
            $acdate=$row["acdate"];
            $acdur=$row["acdur"];
            $accost=$row["accost"];
            $incdesc=$row["Includes"];
            $actransp=$row["actransp"];
            
            echo "<div style='width:250px; padding:10px; float:left;'>
                $actitle <br> $tlname <br> $acdate <br> $acdur <br> $accost <br> $incdesc <br> $actransp
                </div>";
            $i++;            
            if($i % 3 == 0) echo "<div style='clear:both'></div>\n";
            
        }
        if ($i%3) echo "<div style='clear:both'></div>\n";
    }	
	else
{
     echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>';
	 header('Refresh: 5; URL=index.php');
}
?>

try

 

$orderby = '';
if (isset($_POST['sortby'])) {
    switch ($_POST['sortby']) {
        case '0':     $orderby = '';  break;
        case 'costasc': $orderby = " ORDER BY accost ASC"; break;
        case 'costdesc': $orderby = " ORDER BY accost DESC"; break;
        case 'durasc': $orderby = " ORDER BY acdur ASC"; break;
        case 'durdesc': $orderby = " ORDER BY acdur DESC"; break;
        case 'nameasc': $orderby = " ORDER BY tlname ASC"; break;
        case 'namedesc': $orderby = " ORDER BY tlname DESC"; break;
        case 'dateasc': $orderby = " ORDER BY acdate ASC"; break;
        case 'datedesc': $orderby = " ORDER BY acdate DESC"; break;
        // etc
    }
}


Hi Barand,

sorry i didnt get u.

I have total 16 records in the database. For example if i select Duration 8 days and do a search, it will give me 4 records which are not sorted in any order. Now while on the results page with the 4 records if i select Sort by "Price Ascending" then the page clears the 4 records and displays all the 16 records sorted by Price Asc.

 

So basically this dropdown is clearing the search results. What i want is, while on the results page with 4 records I should be able to flick between the sort by dropdown list for these 4 records in either Price ASC/DESC or Duration ASC/DESC or Date ASC/DESC or Teamleader Name ASC/DESC.

Use session.

 

When you create the selection options, set the selected one to the one saved in the session.

 

It's easier to put the options and values in an array and loop through them to create the options and test which should be selected. In the case of included activities loop through the table data.

hi barand, thank you.
On the results page i have added following code:

<?php
session_start();
foreach(array('duration', 'datepicker', 'transport', 'activity') as $name)
{
  $_SESSION[$name] = (isset($_POST[$name])) ? $_POST[$name] : "";
}
echo "<pre>";
print_r($_SESSION);
echo "</pre>\n";
?> 

when i do the search it shows the saved session contents. Am I on a right track ?
i have been trying to get my head over how to do this session part in my code; but I have no idea, I will be really grateful if you can help me please.

A couple of samples

 

<?php
$duration_options = '';
for ($d=7; $d<=14; $d++) {
    $sel = $d==$_SESSION['duration'] ? "selected='selected" : '';
    $duration_options .= "<option $sel value='$d'> $d</option>";
}

$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="duration" id="duration">
     <option value="">Any</option>
     <?php echo $duration_options ?>
</select>


<select name="transport" id="transport">
    <option selected="selected" value="0">Any</option>
    <?php echo $transport_options ?>
</select>

hi barand, thank you for your help, much appreciated.

it throws Undefined variable error on red marked lines. do i use FOREACH to those check boxes.

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<?php
$duration_options = '';
for ($d=7; $d<=14; $d++) {
    $sel = $d == $_SESSION['duration'] ? "selected='selected" : '';
    $duration_options .= "<option $sel value='$d'> $d</option>";
}

$transport_options = '';
$trans = array('included', 'excluded');
foreach ($trans as $o) {
    $sel = $o == $_SESSION['transport'] ? "selected='selected" : '';
    $transport_options .= "<option $sel value='$o'> $o</option>";
}

$_SESSION["datepicker"] = $_POST["datepicker"];

$_SESSION['activity'] = $_POST['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="400" border="0" cellspacing="0" cellpadding="0">
        <tr>
      <td>Duration (days)</td>
      <td><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%">
      <input type="text" id="datepicker" name="datepicker" />
      </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>Transportation</td>
      <td><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>Fishing</td>
      <td><input name="activity[]" type="checkbox" id="chkfishing" value="1" /></td>
    </tr>
    <tr>
      <td>Gliding</td>
      <td><input name="activity[]" type="checkbox" id="chkgliding" value="2" /></td>
    </tr>
    <tr>
      <td>Flying</td>
      <td><input name="activity[]" type="checkbox" id="chkflying" value="3" /></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>

You have checkbox descriptions and values (incid) in your db. Query the table to create checkboxes. (This must be about the third time I've said this)

 

edit.

 

You are using sessions so you need session_start() at the top of the script.

 

You are using $_SESSION values before you have set them

Edited by Barand

Hi barand, thank you for your help.

I have now created a checkbox from db query

My session code for textbox (datepicker) and checkboxex (activities) seems to be not right, could you please have a look.

 

index.php

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<?php
include 'db.inc.php';
?>
<?php
session_start();

$duration_options = '';
for ($d=7; $d<=14; $d++) {
    $sel = $d == $_SESSION['duration'] ? "selected='selected" : '';
    $duration_options .= "<option $sel value='$d'> $d</option>";
}

$transport_options = '';
$trans = array('included', 'excluded');
foreach ($trans as $o) {
    $sel = $o == $_SESSION['transport'] ? "selected='selected" : '';
    $transport_options .= "<option $sel value='$o'> $o</option>";
}


$activity_options = '';
for ($d=1; $d<=3; $d++) {
    $sel = $d == $_SESSION['activity'] ? "checked='checked" : '';
	$activity_options .= "<input $sel value='$d'> $d</option>";
}

$datepicker_options['datepicker'] = 'datepicker';
$_SESSION['datepicker'] = $datepicker_options['datepicker'];


?>
<!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="400" border="0" cellspacing="0" cellpadding="0">
        <tr>
      <td>Duration (days)</td>
      <td><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%">
      <input name="datepicker" type="text" id="datepicker" />
      </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td>Transportation</td>
      <td><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
$query="SELECT * FROM inclusion ORDER BY incid";
$test= mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($test)){
$activityname = $row["incdesc"];
$activityid = $row["incid"];
"<br/>";
"<br/>";
echo "<input type=\"checkbox\" name=\"activity[]\" value=\"$activityid\"> $activityname";
echo "<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); ?>

listactivities.php

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<?php
include 'db.inc.php';
?>
<?php
session_start();
foreach(array('duration', 'datepicker', 'transport', 'activity') as $name)
{
  $_SESSION[$name] = (isset($_POST[$name])) ? $_POST[$name] : "";
}
echo "<pre>";
print_r($_SESSION);
echo "</pre>\n";
?> 
<form name="form1" method="post" action="">
<select name="sortby" id="sortby" onChange="this.form.submit()">
      	<option selected="selected" value="0">Sorty by</option>
        <option value="costasc">Price Ascending</option>
        <option value="costdesc">Price Descending</option>
        <option value="durasc">Duration Ascending</option>
        <option value="durdesc">Duration Descending</option>
        <option value="nameasc">Teamleader Name ASC</option>
        <option value="namedesc">Teamleader Name DESC</option>
        <option value="dateasc">Date Ascending</option>
		<option value="datedesc">Date Descending</option>
      </select>
</form>
<?php

$orderby = '';
if (isset($_POST['sortby'])) {
    switch ($_POST['sortby']) {
        case '0':     $orderby = '';  break;
        case 'costasc': $orderby = " ORDER BY accost ASC"; break;
        case 'costdesc': $orderby = " ORDER BY accost DESC"; break;
        case 'durasc': $orderby = " ORDER BY acdur ASC"; break;
        case 'durdesc': $orderby = " ORDER BY acdur DESC"; break;
        case 'nameasc': $orderby = " ORDER BY tlname ASC"; break;
        case 'namedesc': $orderby = " ORDER BY tlname DESC"; break;
        case 'dateasc': $orderby = " ORDER BY acdate ASC"; break;
        case 'datedesc': $orderby = " ORDER BY acdate DESC"; break;
        // etc
    }
}

?>
<p></p><p></p>
<?php
    $where = array();
    $whereclause = '';
    
    if (!empty($_POST['duration'])) {
        $val = intval($_POST['duration']);
        $where[] = "(acdur = $val)";
    }
    
    if (!empty($_POST['transport'])) {
        $val = mysql_real_escape_string($_POST['transport']);
        $where[] = "(actransp = '$val')";
    }
	
	    if (!empty($_POST['datepicker'])) {
        $val = mysql_real_escape_string($_POST['datepicker']);
        $where[] = "(acdate = '$val')";
    }
    
   // assuming you change you checkbox names
    if (isset($_POST['activity'])) {
        $val = join(",", array_map('intval', $_POST['activity']));
        $where[] = "(incl_activity.incid IN ($val))";
    }
	    
    if (count($where)) $whereclause = "WHERE " . join(' AND ', $where);
			
$query = "SELECT activities.*, teamleader.tlname, GROUP_CONCAT(incdesc SEPARATOR ', ') as Includes  
FROM activities
JOIN incl_activity on activities.acid = incl_activity.acid
JOIN inclusion on incl_activity.incid = inclusion.incid
JOIN teamleader on activities.tlid2 = teamleader.tlid
$whereclause
GROUP BY activities.acid
$orderby";

//ORDER BY teamleader.tlname ASC";
			
	//echo $query;
	$test= mysql_query($query) or die(mysql_error());
	
	    if(mysql_num_rows($test))
    {
        $i=0;    
        while($row = mysql_fetch_assoc($test)){
        
            $actitle=$row["actitle"];
            $tlname=$row["tlname"];
            $acdate=$row["acdate"];
            $acdur=$row["acdur"];
            $accost=$row["accost"];
            $incdesc=$row["Includes"];
            $actransp=$row["actransp"];
            
            echo "<div style='width:250px; padding:10px; float:left;'>
                $actitle <br> $tlname <br> $acdate <br> $acdur <br> $accost <br> $incdesc <br> $actransp
                </div>";
            $i++;            
            if($i % 3 == 0) echo "<div style='clear:both'></div>\n";
            
        }
        if ($i%3) echo "<div style='clear:both'></div>\n";
    }	
	else
{
     echo '<div align=center style="margin:20px; font-family:Arial, Helvetica, sans-serif; font-size: 20px; font-weight:bold; color: #ae1919;">Your search did not match any results.</div>';
	 header('Refresh: 5; URL=index.php');
}
	
?>
<?php mysql_free_result($test); ?>

Edited by bickyz

what is this supposed to do?

 

$activity_options = '';
for ($d=1; $d<=3; $d++) {
    $sel = $d == $_SESSION['activity'] ? "checked='checked" : '';
	$activity_options .= "<input $sel value='$d'> $d</option>";
}

example

 

<form action="" method="post">
<?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($id, $desc) = mysql_fetch_row($test)) {
        $chk = in_array($id, $_SESSION['activity']) ? "checked='checked'" : '';
        echo "<input type=\"checkbox\" name=\"activity[]\" value=\"$id\" $chk /> $desc <br>";
    }
    
?>
<input type="submit" name="btnSubmit" value="Submit">
</form>

hi barand, thank you for the help.

it throws following error now,

Notice: Undefined index: duration in index.php on line 40
Notice: Undefined index: transport in index.php on line 74

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
?>
<?php
include 'db.inc.php';
?>
<?php
session_start();
?>
<!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); ?>
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.