Jump to content

Why doesnt this work.


deansaddigh

Recommended Posts

I have this code, which should display images based on wether fields are checked or not.

 

					//This is where code should go! ?>

					<?



                    	if ($cottage[0]{'pets'} == 'checked')
					{
				?>				
                    	<div class='icons'><img src='images/Pets.jpg' alt='Pets allowed'></div>				
				<?			
					}
					else
					{
				?>
                    	<div class='icons'><img src='images/noPets.jpg' alt='No pets'></div>
				<?			
					}

					if($cottage[0]{'linen'} == 'linen' || $cottage[0]{'linen'} == 'both')
					{
				?>
					<div class='icons'><img src='images/linen.jpg' alt='Linen provided'></div>
				<?			
					}
				?>
				<?			
					if ($cottage[0]{'linen'} == 'towels' || $cottage[0]{'linen'} == 'both')
					{
				?>
					<div class='icons'><img src='images/towels.jpg' alt='Towels provided'></div>
				<?
					}
				?>
				<?
					if ($cottage[0]{'changeOver'} == 'Friday')
				{
				?>
                    	<div class='icons'><img src='images/friday.jpg' alt='Friday changeover'></div>
				<?
				}

 

 

And heres the code for the entire page.

 

<?php	
require_once('admin/lib/scripts/php/functions.php');
dbConnect();
session_start();

/*top drop down search*/
$locationsQuery = dbExec("SELECT DISTINCT p.county_id, c.county 
FROM properties p 
JOIN county c
ON p.county_id = c.id WHERE status = 'online' ORDER BY county ASC");





//set up defaults
$arrivalDate = '';
$departureDate = '';
$location = '';
$sleeps ='';
$pets ='';
$shortBreaks ='';
$coastal ='';
$openFire ='';
$garden ='';

if(isset($_SESSION['rand'])){
	$rand = $_SESSION['rand'];
}else{
	$rand = '';
}

if (empty($rand)) {
	srand((float)microtime()*1000000);
	$rand = "0.".rand();
	$_SESSION['rand'] = $rand;
}

$order = 'RAND('.$rand.')';
$limit = 5;
$page = 1;

if(isset($_GET['short'])){
	$shortBreaks = 'checked';
}

if(isset($_GET['location'])){
	$location = $_GET['location'];
}

//Check for post variables
if(isset($_POST['arrival'])){
	$arrivalDate = $_POST['arrival'];
	$departureDate = $_POST['departure'];
	$location = $_POST['location'];
	$sleeps = $_POST['sleeps'];
	$pets = $_POST['pets'];
	if(isset($_POST['short'])){
		$shortBreaks = ($_POST['short'] == 'checked')? 'checked': '';
	}
	if(isset($_POST['coastal'])) $coastal = 'checked';
	if(isset($_POST['openFire'])) $openFire = 'checked';
	if(isset($_POST['garden'])) $garden = 'checked';
	if(isset($_POST['order'])) $order = $_POST['order'];
	if(isset($_POST['limit'])) $limit = $_POST['limit'];
}

//Check for paging variables
if(isset($_GET['page'])){
	$arrivalDate = $_GET['arrivalDate'];
	$departureDate = $_GET['departureDate'];
	$location = $_GET['location'];
	$sleeps =$_GET['sleeps'];
	$pets =$_GET['pets'];
	$shortBreaks =$_GET['shortBreaks'];
	$coastal =$_GET['coastal'];
	$openFire =$_GET['openFire'];
	$garden =$_GET['garden'];
	$order = $_GET['order'];
	$limit = $_GET['limit'];
	$page = $_GET['page'];
}

//location filter
if($location <> ''){
	$locationSQL = ' AND county_id = \''.$location.'\'';
}else{
	$locationSQL = '';
}

//sleeps filter
if($sleeps <> ''){
	$sleepsSQL = ' AND maxGuests = '.$sleeps.'';
}else{
	$sleepsSQL = '';
}

//pets filter
if($pets == 'yes'){
	$petsSQL = ' AND pets = \'checked\'';
}else if($pets == 'no'){
	$petsSQL = ' AND pets != \'checked\'';
}else{
	$petsSQL = '';
}

//coastal filter
if($coastal <> ''){
	$coastalSQL = ' AND costal = \'checked\'';
}else{
	$coastalSQL = '';
}

//open fire filter
if($openFire <> ''){
	$openFireSQL = ' AND openFire = \'checked\'';
}else{
	$openFireSQL = '';
}

//garden filter
if($garden <> ''){
	$gardenSQL = ' AND garden = \'checked\'';
}else{
	$gardenSQL = '';
}

//short breaks filter
if($shortBreaks <> ''){
	$shortBreaksSQL = ' AND shortBreaks = \'checked\'';
}else{
	$shortBreaksSQL = '';
}

//calculate arrival and departure dates
$dateSQL = '';
if(($arrivalDate <> '' && $arrivalDate <> 'Arrival') || ($departureDate <> '' && $departureDate <> 'Departure')){

	if($arrivalDate == '' || $arrivalDate == 'Arrival'){
		//only departure date entered
		$departure_date = explode("/", $departureDate);
		$departure_date = $departure_date[2].$departure_date[1].$departure_date[0];
		$dateSQL = " AND p.id NOT IN (SELECT property_id FROM bookings WHERE (('$departure_date' < departure_date AND '$departure_date' > arrival_date) OR (departure_date = '$departure_date')))";
	}else if($departureDate == '' || $departureDate == 'Departure'){
		//only arrival date entered
		$arrival_date = explode("/", $arrivalDate);
		$arrival_date = $arrival_date[2].$arrival_date[1].$arrival_date[0];
		$dateSQL = " AND p.id NOT IN (SELECT property_id FROM bookings WHERE (('$arrival_date' > arrival_date AND '$arrival_date' < departure_date) OR (arrival_date = '$arrival_date')))";
	}else{
		//both dates entered
		$departure_date = explode("/", $departureDate);
		$departure_date = $departure_date[2].$departure_date[1].$departure_date[0];
		$arrival_date = explode("/", $arrivalDate);
		$arrival_date = $arrival_date[2].$arrival_date[1].$arrival_date[0];

		$dateSQL = " AND p.id NOT IN (SELECT property_id FROM bookings WHERE (('$arrival_date' < arrival_date AND '$departure_date' > arrival_date) OR ('$arrival_date' < departure_date AND '$departure_date' > departure_date ) OR ('$arrival_date' >= arrival_date AND '$departure_date' <= departure_date )))";

	}

}

//get properties
$cottageQueryAll = dbExec("SELECT p.*, (SELECT thumb FROM images WHERE product_id = p.id LIMIT 1) AS thumb FROM properties p WHERE p.status = 'online' $dateSQL $locationSQL $sleepsSQL $petsSQL $coastalSQL $openFireSQL $gardenSQL $shortBreaksSQL");

//calculate pages
$totalCottages = mysql_num_rows($cottageQueryAll);
if($limit > ''){
	$pages = ceil($totalCottages / $limit);
}else{
	$pages = 0;
}

//calculate order by
$orderBy = ($order <> '')? 'ORDER BY '.$order : '';
if($limit <> ''){
	if($page == 1){
		$pageStart = 0;
	}else{
		$pageStart = ($page-1) * $limit;
	}
	$limitBy = 'LIMIT '.$pageStart.','.$limit;
}else{
	$limitBy = '';
}

$cottageQuery = dbExec("SELECT p.*, (SELECT thumb FROM images WHERE product_id = p.id LIMIT 1) AS thumb FROM properties p WHERE p.status = 'online' $dateSQL $locationSQL $sleepsSQL $petsSQL $coastalSQL $openFireSQL $gardenSQL $shortBreaksSQL $orderBy $limitBy");

$page_id = 'home';
$title = 'Home';
include('lib/includes/header.php');

//$arrivalSQL = "SELECT * FROM bookings WHERE (('$arrival_date' < arrival_date AND '$departure_date' > arrival_date) OR ('$arrival_date' < departure_date AND '$departure_date' > departure_date ) OR ('$arrival_date' >= arrival_date AND '$departure_date' <= departure_date ))";


?>
<!-- START OF MAIN CONTENT -->

<?	include('lib/includes/searchBar.php');

?>

<div id='listContents'>
    	<form method='POST' name='filter' id='filter' action='list.php' style="padding:0; margin:0;">
    		<div class="thinTitle">Filter cottages</div>
		<div class="filterBox">
			<input name="departure" value="<?=$departureDate?>" type="hidden" />
            	<input name="arrival" value="<?=$arrivalDate?>" type="hidden" />
                <input name="short" value="<?=$shortBreaks?>" type="hidden" />
                <table border='0'>
                    <tr>
                        <td>
                            <select name='pets' class='searchDropDown'>
                                <option value=''>Pets</option>
                                <option value='yes' <? if ( $pets == 'yes' ){echo 'selected';}?>>Yes</option>
                                <option value='no' <? if ( $pets == 'no' ){echo 'selected';}?>>No</option>
                            </select>
                        </td>
                        <td>
                            <select name='location' class='searchDropDown'>
                                <option value=''>Location</option>
                                <?
                                while($locationResults = mysql_fetch_array($locationsQuery)){
                                ?>
                                <option value='<?=$locationResults['county_id']?>' <? if($location == $locationResults['county_id']){echo 'selected';}?>><?=$locationResults['county']?></option>
                                <?
                                }
                                ?>
                            </select>
    
                        </td>
                        <td width='200'>
                            <select name='sleeps' class='searchDropDown'>
                                <option value=''  <? if ( $sleeps == "" ){echo 'selected';}?>>Sleeps</option>
                                <option value='1' <? if (  $sleeps == '1' ){echo 'selected';}?>>1</option>
                                <option value='2' <? if (  $sleeps == '2' ){echo 'selected';}?>>2</option>
                                <option value='3' <? if (  $sleeps == '3' ){echo 'selected';}?>>3</option>
                                <option value='4' <? if (  $sleeps == '4' ){echo 'selected';}?>>4</option>
                                <option value='5' <? if (  $sleeps == '5' ){echo 'selected';}?>>5</option>
                                <option value='6' <? if (  $sleeps == '6' ){echo 'selected';}?>>6</option>
                                <option value='7' <? if (  $sleeps == '7' ){echo 'selected';}?>>7</option>
                                <option value='8' <? if (  $sleeps == '8' ){echo 'selected';}?>>8</option>
                                <option value='9' <? if (  $sleeps == '9' ){echo 'selected';}?>>9</option>
                                <option value='10' <? if (  $sleeps == '10' ){echo 'selected';}?>>10</option>
                            </select>
                        </td>
                        <td>
                            <div class='button'><a href="javascript:document.getElementById('filter').submit()">Refresh</a></div>
                        </td>
                    </tr>
                </table>
                <table class='blueText'>
                    <tr>
                        <td>Coastal</td>
                        <td width='110'><input type="checkbox" name="coastal" value='checked' <?=$coastal?>></td>
                        <td>Open Fire</td>
                        <td width='100'><input type="checkbox" name="openFire" value='checked' <?=$openFire?>></td>
                        <td>Garden</td>
                        <td><input type="checkbox" name="garden" value='checked' <?=$garden?>></td>
                    </tr>
                </table>
            </div>

            <div class='yellowLine' style="margin:10px 0 10px 0;"></div>
    
            <table border='0' bgcolor='#252645' width="100%">
                <tr>
                    <td width='200px' valign='middle' style="padding-left:10px;">Cottage results (<?=$totalCottages?>):</td>
                    <td width='150px'  valign='middle'></td>
                    <td valign='middle' width="100px">Show: 
                        <select name='limit' class='searchDropDownNew' onchange='document.filter.submit()'>
                            <option value='5' <? if ( $limit == '5' ){echo 'selected';}?>>5</option>
                            <option value='10'<? if ( $limit == '10' ){echo 'selected';}?>>10</option>
                            <option value='20'<? if ( $limit == '20' ){echo 'selected';}?>>20</option>
                            <option value='30'<? if ( $limit == '30' ){echo 'selected';}?>>30</option>
                            <option value='40'<? if ( $limit == '40' ){echo 'selected';}?>>40</option>
                            <option value='50'<? if ( $limit == '50' ){echo 'selected';}?>>50</option>
                            <option value=''<? if ( $limit == '' ){echo 'selected';}?>>All</option>
                        </select>
                    </td>
                    <td valign='middle'>Order by: 
                        <select name='order' class='searchDropDownNew' onchange='document.filter.submit()'>
                            <option value=''>Please select</option>
                            <option value='location ASC'<? if ( $order == 'location ASC' ){echo 'selected';}?>>Location A-Z</option>
                            <option value='location DESC'<? if ( $order == 'location DESC' ){echo 'selected';}?>>Location Z-A</option>
                            <option value='propertyName ASC'<? if ( $order == 'propertyName ASC' ){echo 'selected';}?>>Name A-Z</option>
                            <option value='propertyName DESC'<? if ( $order == 'propertyName DESC' ){echo 'selected';}?>>Name Z-A</option>
                            <option value='maxGuests ASC'<? if ( $order == 'maxGuests ASC' ){echo 'selected';}?>>Sleeps Low-High</option>
                            <option value='maxGuests DESC'<? if ( $order == 'maxGuests DESC' ){echo 'selected';}?>>Sleeps High-Low</option>
                        </select>
                    </td>
                </tr>
            </table>
	</form>
        <br />
        
        <div id='searchResultsContainer'>

        <? 	
        if(mysql_num_rows($cottageQuery)){
            while($cottage = mysql_fetch_array($cottageQuery)){
                if($cottage['thumb']<>''){
                    $img = "<a href='details.php?id=".$cottage['id']."'><img src='admin/images/properties/".$cottage['thumb']."' class='imageBorder'></a>";
                }else{
                    $img = " ";
                }

			$thisSat = date("Ymd", strtotime("saturday"));
			$thisSun = date("Ymd", strtotime("sunday"));
			$weekendCheckQuery = dbExec("SELECT property_id FROM bookings WHERE (('$thisSat' < arrival_date AND '$thisSun' > arrival_date) OR ('$thisSat' < departure_date AND '$thisSun' > departure_date ) OR ('$thisSat' >= arrival_date AND '$thisSun' <= departure_date )) AND property_id = ".$cottage['id']."");
			if(mysql_num_rows($weekendCheckQuery)){
				$thisWeekend = '<span style="padding: 0px 0 0px 3px; clear:both; display:block;"> </span>';
			}else{
				$thisWeekend = '<span style="padding: 5px 0 5px 3px; clear:both; display:block;">Available this weekend</span>';
			}

        ?>
            
            <div class='orangeBorderTop'> </div>
            <div class='orangeBorderMiddle'>	

            <table border='0' class='blueText2'  style='margin:0px'>
                <tr>
                    <td width='100'><?=$img?></td>
                    <td valign='top' width='370'>
                        <a href='details.php?id=<?=$cottage['id']?>'><span class='blueTextBold'><?=$cottage['propertyName']?> - <?=$cottage['location']?></span></a><br />
                        <a href='details.php?id=<?=$cottage['id']?>'class='blueText2'><?=$cottage['list_description']?>...[more]</a>					
                    </td>
                    <td width='20'></td>
                    <td valign="top">
                    	<img src="images/beds/<?=$cottage['bedrooms']?>.png" /><img src="images/sleeps/<?=$cottage['maxGuests']?>.png" /><br />
                        <?=$thisWeekend?>
                        <a href='details.php?id=<?=$cottage['id']?>'><img src='images/take.gif' border='0'></a>
                    <? 
					//This is where code should go! ?>

					<?



                    	if ($cottage[0]{'pets'} == 'checked')
					{
				?>				
                    	<div class='icons'><img src='images/Pets.jpg' alt='Pets allowed'></div>				
				<?			
					}
					else
					{
				?>
                    	<div class='icons'><img src='images/noPets.jpg' alt='No pets'></div>
				<?			
					}

					if($cottage[0]{'linen'} == 'linen' || $cottage[0]{'linen'} == 'both')
					{
				?>
					<div class='icons'><img src='images/linen.jpg' alt='Linen provided'></div>
				<?			
					}
				?>
				<?			
					if ($cottage[0]{'linen'} == 'towels' || $cottage[0]{'linen'} == 'both')
					{
				?>
					<div class='icons'><img src='images/towels.jpg' alt='Towels provided'></div>
				<?
					}
				?>
				<?
					if ($cottage[0]{'changeOver'} == 'Friday')
				{
				?>
                    	<div class='icons'><img src='images/friday.jpg' alt='Friday changeover'></div>
				<?
				}





					 //end code
				?>
                    </td>
                </tr>
            </table>

            </div>
            <div class='orangeBorderBottom'> </div>	
        <?
            }	
        }else{
        ?>			
            <div class='blueText'><p class='font1'>No results found.</p></div>
        <?
        }
        ?>

            <div class='paginationBar'>
            	<?
			$queryString = '&limit='.$limit.'&order='.$order.'&garden='.$garden.'&openFire='.$openFire.'&coastal='.$coastal.'&shortBreaks='.$shortBreaks.'&pets='.$pets.'&sleeps='.$sleeps.'&location='.$location.'&departureDate='.$departureDate.'&arrivalDate='.$arrivalDate;
			for($i=1; $i<=$pages; $i++){
				if($i < ($pages)){
					if($i == $page){
						echo '<strong>'.$i.'</strong> | ';
					}else{
						echo '<a href="list.php?page='.$i.$queryString.'">'.$i.'</a> | ';
					}
				}else{
					if($i == $page){
						echo '<strong>'.$i.'</strong>';
					}else{
						echo '<a href="list.php?page='.$i.$queryString.'">'.$i.'</a>';
					}
				}
			}
			?>
            </div>
        </div>
</div>
    <!-- END OF MAIN CONTENT -->

<?	include('lib/includes/brochureBar.php');
?>


<BR clear='all'>


<?php
include('lib/includes/footer.php');
?>

 

Any help would be brilliant

 

thanks in advance guys

Link to comment
Share on other sites

Hi and thank you, i have changed them all accordingly , but its still not working.

if you can go here

 

http://www.dhcottages.co.uk/testsite/list.php?page=1&limit=5&order=RAND%280.1242%29&garden=&openFire=&coastal=&shortBreaks=&pets=&sleeps=&location=&departureDate=&arrivalDate=

 

you can see that every listing has the dog crossed out, it if you click more details, it takes you to the page with the icons that should be visible

Link to comment
Share on other sites

not all of them have the dog crosses out by the way, but I see what the problem is

 

I try printing the values of the variables you are testing in the if statements to the screen and see if they have what you expect them to have. for example

print $cottage[0]{'pets'};

 

that should help pinpoint where the problem lies

 

Edit: oops, you posted before i saw it, if your problem is solved, then you can click the mark solved button in the bottom of the thread

Link to comment
Share on other sites

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.