Jump to content

filter search results


teknojunkey

Recommended Posts

hi,

 

I have a search page with a checkbox $departuk that returns the value "true" if checked.

 

I want to return search results if this returns true and the flag 'Y' is available

 

		
if ($departuk == "true"){
		if ($data[$i]['departuk'] == 'Y'){
			$result = $obj->result;
		}
		else{
			echo "do some thing else";
		}
	else{
			echo"there was a problem";
	}

 

any pointers / advice is appreciated

thanks

Link to comment
https://forums.phpfreaks.com/topic/227218-filter-search-results/
Share on other sites

I get this error .. Parse error: syntax error, unexpected T_ELSE in ....../simple_search.php on line 100

 

here is the full page ...

<?php

$searchParam='';
$childage='';
if($_POST)
{
	$lineid=trim($_POST['lineid']);
	$shipid=trim($_POST['shipid']);
	$regionid=trim($_POST['regionid']);
	$sdate=trim($_POST['sdate']);
	$edate=trim($_POST['edate']);
	$adults=trim($_POST['adults']);
	$children=trim($_POST['children']);
	$departuk=trim($_POST['departuk']);
echo $departuk;






	for($i=1;$i<=$children;$i++)
	{
		$childage.='<child age="'.trim($_POST['childage'.$i]).'" />';
		if($i==1)			
			$ca=trim($_POST['childage'.$i]);
		else 
			$ca=",".trim($_POST['childage'.$i]);	
	}

	if(!empty($lineid))
		$searchParam.=' lineid="'.$lineid.'"';

	if(!empty($shipid))
		$searchParam.=' shipid="'.$shipid.'"';

	if(!empty($regionid))
		$searchParam.=' regionid="'.$regionid.'"';

	if (!empty($sdate) && !empty($edate))
		$searchParam.=' startdate="'.$sdate.'" enddate="'.$edate.'"';
	elseif (!empty($sdate))
		$searchParam.=' startdate="'.$sdate.'" enddate="'.$edate.'"';

	$searchParam.=' adults="'.$adults.'"';
	$searchParam.=' children="'.$children.'"';

}
//echo $ca;
//startdate="2011-02-01" enddate="2011-02-28" lineid="22" adults="2" children="1" 
if(!empty($childage))
	$encodeString=urlencode('<?xml version="1.0"?><request><auth username="...." password="...." /><method action="simplesearch" sitename="www.site.co.uk" currency="GBP" status="Test" type="cruise"><searchdetail resultkey="default" sid="...." type="cruise" '.$searchParam.'>'.$childage.'</searchdetail></method></request>');
else 
	$encodeString=urlencode('<?xml version="1.0"?><request><auth username="...." password="...." /><method action="simplesearch" sitename="www.......co.uk" currency="GBP" status="Test" type="cruise"><searchdetail resultkey="default" sid="....." type="cruise" '.$searchParam.'></searchdetail></method></request>');
//echo $encodeString;exit;		
$ch = curl_init("http://fusionapi.traveltek.net/0.9/interface.pl");

curl_setopt( $ch, CURLOPT_URL, "http://fusionapi.traveltek.net/0.9/interface.pl?xml=".$encodeString); // url to post

curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 200);
//curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above

$tmp = curl_exec( $ch ); // runs the post
curl_close($ch); 

$doc = simplexml_load_string($tmp);
//echo $doc->results->cruise['name'];
/*echo "<pre>";
print_r($doc);
exit;*/

/*for($i=0;$i<count($doc->results->cruise[9]->regions->region);$i++)
{
	echo $doc->results->cruise[9]->regions->region[$i]['name'];
}
exit;*/
//$arrRegion=explode(";",$region);
$sessionKey=$doc->request->method['sessionkey'];
//echo count($doc->results->cruise);
//echo $doc->results->cruise->regions->region['name'];
//print_r($doc->results->cruise);
//print_r($_SESSION['qResult']);
//exit;
include 'pagination_class.php';
        // Create the pagination object
           
    	$starting=0;
$recpage = 10;//number of records per page

$obj = new Pagination_class($doc->results->cruise,$starting,$recpage);	

	if ($departuk == "true"){
		if ($data[$i]['departuk'] == 'Y'){
			$result = $obj->result;
		}
		else {
			echo "do some thing else";
		}
	else {
			echo "there was a problem";
	}
  
//$result = $obj->result;
//print_r($result);
?>

 

this is where the data is displyed ....

 

<form name="form1" action="testpage.php" method="POST">	
	<input type="hidden" value="<?php echo $lineid; ?>" name="lineid">
	<input type="hidden" value="<?php echo $shipid; ?>" name="shipid">
	<input type="hidden" value="<?php echo $regionid; ?>" name="regionid">
	<input type="hidden" value="<?php echo $sdate; ?>" name="sdate">
	<input type="hidden" value="<?php echo $edate; ?>" name="edate">
	<input type="hidden" value="<?php echo $adults; ?>" name="adults">	
	<input type="hidden" value="<?php echo $children; ?>" name="children">	
	<input type="hidden" value='<?php echo $ca; ?>' name="childage">	
	<input type="hidden" value='<?php echo $searchParam; ?>' name="sp">
		<table border="1" align="center" width="40%">

		<tr><TD colspan="2">

		<div id="page_contents">
			<?if(count($result)!=0){?>
				<table border="1" align="center" width="100%">									
				<tr><TD colspan="2"><? echo $obj->anchors; ?></TD></tr>
				<tr><TD colspan="2"><? echo $obj->total; ?></TD></tr>
				</table>
				<?php 					
				$counter = $starting + 1;					
				foreach ($result as $data)  {
					$region='';
					$ports='';
					$ukl='';
					for($i=0;$i<count($data->regions->region);$i++)
					{
						if(empty($region))
							$region.= $data->regions->region[$i]['name'];
						else 
							$region.=", ". $data->regions->region[$i]['name'];
					}
					for($i=0;$i<count($data->ports->port);$i++)
					{
						if(empty($ports))
							$ports= "<b>".$data->ports->port[$i]['name']."<b>";
						else 
							$ports.=" ><b> ". $data->ports->port[$i]['name']."<b>";
					}
					for($i=0;$i<count($data['departuk']);$i++)
					{
						if(empty($ukl))
							$ukl= "<b>".$data[$i]['departuk']."<b>";
						else 
							$ukl.=" ><b> ". $data[$i]['departuk']."<b>";

					}


			?>

				<div class="cruiseresult2" id="longrow_<?php echo $data['resultno'];?>">    
			    <div id="shortrow_<?php echo $data['resultno'];?>">
			        <div class="resultInfo">
			    
			            <div class="left">
			            	<h2 class="cruisename"><img height="15" width="20" src="http://static0.traveltek.net/images/dynapack/cruise.gif" alt="Cruise" /> <?php echo $data['name']; ?>  - <?php echo $region;?></h2>
			                
					<p class="cruisedetail2">On the <a href="line_detail.php?sessionkey=<?php echo $sessionKey; ?>&chosencruise=<?php echo $data['resultno'];?>&lineid=<?php echo $data->line['id']?>"><?php echo $data->line['name'];?></a> ship <a href="/fusion/detailship3.pl?sessionkey=<?php echo $sessionKey;?>&chosencruise=<?php echo $data['resultno'];?>&shipid=<?php echo $data->ship['id'];?>"><?php echo $data->ship['name'];?></a> <?php echo date('jS M Y',strtotime($data['enddate']));?> for <?php echo $data['nights'];?> Nights</p>
			                <p><b>ship rating :</b> <img src="http://static3.traveltek.net/images/dynapack/star10.gif" style="margin-top: 3px;"><img src="http://static3.traveltek.net/images/dynapack/star10.gif" style="margin-top: 3px;"><img src="http://static3.traveltek.net/images/dynapack/star10.gif" style="margin-top: 3px;"><img src="http://static3.traveltek.net/images/dynapack/star10.gif" style="margin-top: 3px;"></p>
			            
<?php echo $data[$i]['departuk'];
						if ($data[$i]['departuk'] == 'N'){
							echo "works";
						}
						else{
							echo "disnywork";
						}
?>
</div>
			            <div class="right" style="text-align: center;">
			            	<div class="cruiseresult2-img">
							   <a href="<?php echo $data->ship['imageurl'];?>" rel="lightbox"><img height="68px" width="118px" src="<?php echo $data->ship['smallimageurl']?>" style="border: 1px solid rgb(153, 153, 153);"></a>

							</div><div class="clear"></div>
							<img border="0" src="<?php echo $data->line['logourl'];?>" alt="<?php echo $data->line['name'];?>" title="<?php echo $data->line['name'];?>">
			            </div>
			            <div class="clear"></div>
			            
			            <div style="font-weight: bold;" class="ports">cruise ports : <?php echo $ports;?></div>

					</div>

			        <div class="clear" style="height: 10px;"></div>
			        
			        <table width="100%" cellspacing="0" cellpadding="0">
			        	<tbody><tr>
			            	<td>
			                    <div class="priceColLeft">
			                        <table cellspacing="0" cellpadding="0" name="pricegrid" class="pricegrid">
										<tbody><tr>
										    <th width="120px" style="padding: 0pt 0pt 0pt 10px;"> </th>
										    <th width="70px" align="left">inside</th>											    
										</tr><tr>
										    <td style="padding: 0pt 0pt 0pt 10px; color: rgb(51, 51, 51);">Cruise Only</td>
										    <td><b><?php if($data['startprice']>0) echo "&#163;".$data['startprice'];else echo "-";?></b></td>
										    
										</tr></tbody>
									</table>
			                    </div>
			                </td>
			                <td valign="bottom">
								<div class="priceColRight">
			                    	
			                        <!-- Get Prices -->
			                        <a href="cruise_detail.php?sk=<?php echo $sessionKey; ?>&chosencruise=<?php echo $data['resultno'];?>&sid=<?php echo $data->ship['id'];?>&cid=<?php echo $data['codetocruiseid'];?>"><img src="http://static1.traveltek.net/images/www.simply-cruising.co.uk/btn-moredetails.gif" class="more"></a>
			        			</div>
			                </td>
			            </tr>
			        </tbody></table>

			    </div>
			    <div class="spacer"><img src="http://static2.traveltek.net/images/cruisedemo.traveltek.net/images/spacer.gif"></div>
			</div>
			<?
					$counter ++;
				} ?>
				<table border="1" align="center" width="100%">									
				<tr><TD colspan="2"><? echo $obj->anchors; ?></TD></tr>
				<tr><TD colspan="2"><? echo $obj->total; ?></TD></tr>
				</table>
			<?}else{?>
				<table border="1" align="center" width="100%">
				<tr><TD align="center" colspan="2">No Data Found</TD></tr>
				</table>
			<?}?>
			</TD></tr>
			</table>
		</div>
		</TD></tr>
	</table></form>

 

 

thanks

 

 

 

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.