MMMM, major problem now.
All was good until I added the countries in to allow the user to flick through the countries, and its fine, as I can get the ID from the country to make sure the regions are showing correctly for the country.
But then its when I select a region which are pushed into an array and I cant add the country back into the url to keep the user on the same country until they select another.
http://devchecksafetyfirst.csf.dcmanaged.com/index.php?Country=65
When I select a country i can easily pass the id through, but I cant work out when i select a region how to pass the country id through with it so I can pick it up by using GET and assigning it to a variable.
Have I gone and snookered myself?
<?
session_start();
error_reporting(E_ALL);
ini_set('display_errors','Off');
include("config.php");
$selectCountry=@$_GET['Country'];
// Regions array
if (is_array($_GET['regions'])) {
$regionsArray = array();
foreach($_GET['regions'] as $regions) {
$regionsArray[] = '\\''.$regions.'\\'';
}
$regionData = implode(',', $regionsArray);
$sqlregion = 'AND IdRsrt_Hot IN ('. $regionData .' )';
$sqlregionName = 'WHERE Id_Rsrt IN ('. $regionData .' )';
//echo $sqlregionName;
//echo $regionData;
//echo $sqlregion;
}
// Star rating array
if (is_array($_GET['star'])) {
$starArray = array();
foreach($_GET['star'] as $star) {
$starArray[] = '\\''.$star.'\\'';
}
$starData = implode(',', $starArray);
$sqlstar = 'AND IdCat_Hot IN ('. $starData .' )';
//echo $regionData;
//echo $sqlstar;
}
?>
<!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>
<title>CSF Result Page</title>
<link href="css/style.css" rel="stylesheet" type= "text/css" />
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
</head>
<body>
<div id="wrapper">
<div id="header">
<p style="position:relative; padding:10px;">All countries below:</p>
<? $d=mysql_query("select * from tbl_countries order by Nom_Cntry ASC");
while($f=mysql_fetch_assoc($d)){ ?>
'<a href="index.php?Country=<?=$f['Id_Cntry']?>"><?=$f['Nom_Cntry']?></a>',
<? } ?>
</div>
<div id="result_Center_Block">
<!-- Start of Breadcrumb
<div style="position:relative; width:100%; height:30px; text-align:left; padding-left:12px; padding-top:5px; padding-bottom:20px;">
<p><strong>Showing results for:</strong>
<? if ($sqlstar=="") { ?>
<? } else { ?>
<?=$starData?> star hotels in
<? } ?>
<? if ($sqlregion=="") { ?>
Tunisia
<? } else { ?>
<? $q=mysql_query("select Id_Rsrt, Nom_Rsrt from tbl_resorts " . $sqlregionName . "");
while($n=mysql_fetch_assoc($q)){ ?>
'<?=$n['Nom_Rsrt']?>',
<? } ?>
TUNISIA
<? } ?>
</p>
</div>End of breadcrumb -->
<div id="result_Left_Nav_Bar">
<form name="form1" id="myForm">
<!-- Regions -->
<p><strong>Regions:</strong></p>
<?php
$r=mysql_query("SELECT DISTINCT Id_Rsrt, Nom_Rsrt, IdCntry_Rsrt, Id_show, Act_Hot, IdRsrt_Hot FROM tbl_resorts LEFT JOIN tbl_hotels ON (tbl_resorts.Id_Rsrt=tbl_hotels.IdRsrt_Hot) WHERE (tbl_resorts.IdCntry_Rsrt='".$selectCountry."') AND (tbl_resorts.Id_show='1') AND (tbl_hotels.Act_Hot='1') ORDER BY Nom_Rsrt");
while($q=mysql_fetch_assoc($r)){ ?>
<input type="checkbox" name="regions[]" value="<?=$q['Id_Rsrt']?>" onClick="javascript:checkRefresh()" <?=((in_array($q['Id_Rsrt'], $_REQUEST['regions'])) ? "checked=\\"checked\\" " : "")?> class="inline" /><?=$q['Nom_Rsrt']?></a> <?
$queryNumber = mysql_query("select count(Id_Hot) as total from tbl_hotels where (IdRsrt_Hot='". $q['Id_Rsrt'] ."') and (Act_Hot='1')");
$resultNumber = mysql_fetch_array($queryNumber); ?>
<span style="font-size:12px; color:#900; vertical-align:1px;">[<? echo $resultNumber['total'];?>]</span>
<br/>
<? } ?>
<!-- End Regions -->
<br/>
<p><strong>Star Rating:</strong></p>
<!-- Star Rating -->
<?php
if ($sqlregion==""){
$s=mysql_query("select DISTINCT IdCat_Hot from tbl_hotels WHERE IdCat_Hot IN (1,2,3,4,5) and (Act_Hot='1') order by IdCat_Hot ASC");
while($b=mysql_fetch_assoc($s)){ ?>
<input type="checkbox" name="star[]" value="<?=$b['IdCat_Hot']?>" onClick="javascript:checkRefresh()" <?=((in_array($b['IdCat_Hot'], $_REQUEST['star'])) ? "checked=\\"checked\\" " : "")?> class="inline" /> <?=$b['IdCat_Hot']?> Star<br/>
<? } ?>
<? } else {
$s=mysql_query("select DISTINCT IdCat_Hot from tbl_hotels WHERE IdRsrt_Hot IN (". $regionData .") and (Act_Hot='1') order by IdCat_Hot ASC");
while($b=mysql_fetch_assoc($s)){ ?>
<input type="checkbox" name="star[]" value="<?=$b['IdCat_Hot']?>" onClick="javascript:checkRefresh()" <?=((in_array($b['IdCat_Hot'], $_REQUEST['star'])) ? "checked=\\"checked\\" " : "")?> class="inline" /> <?=$b['IdCat_Hot']?> Star<br/>
<? } ?>
<? } ?>
<!-- End Star rating -->
</form>
</div>
<div id="result_Right_Results">
<?
// Build result query on values of the array
$sql.="select * from tbl_hotels where Act_Hot='1' ";
if ($sqlregion==""){
$sql.= " and IdCntry_Hot='".$selectCountry."'";
} else {
$sql.= "" .$sqlregion . "";
}
if ($sqlstar==""){
$sql.= " and IdCat_Hot IN (1,2,3,4,5,6)";
} else {
$sql.= "" .$sqlstar . "";
}
$sql.= " order by Id_Hot ASC";
$result = mysql_query($sql);
while($q=mysql_fetch_assoc($result)){
?>
<div class="result_Hotel">
<p style="position:relative; margin:10px;"><?=$q['Nom_Hot']?></p>
</div>
<? }
// End Build query
?>
</div>
</div>
<div style="position:relative; width:100%; height:2px; clear:both"></div>
</div>
<?php require_once('footer.php'); ?>
<!-- Black Overlay Script -->
<script type="text/javascript">
jQuery.fn.center = function () {
this.css("position","absolute");
this.css("top", ( $(window).height() - this.height() ) / 2+$(window).scrollTop() + "px");
this.css("left", ( $(window).width() - this.width() ) / 2+$(window).scrollLeft() + "px");
return this;
}
$(document).ready(function() {
$("input:checkbox").on("change", function(e) {
document.form1.submit();
$("#result").hide();
//var v = ($(this).val());
$('<div id="black_overlay"></div>').appendTo('body');
$('<div id="loading">Loading Content</div>').appendTo('body').center();
$.ajax({
//type : "POST",
//url : "sleep.php",
// data : 'v=' + v,
success : function(res) {
$("#loading").remove();
$('#black_overlay').fadeOut('slow', function() {
$('#black_overlay').remove();
// $("#result").text("You chose option " + res).css("display", "inline-block");
});
}
});
});
});
</script>
<!-- End Black Overlay Script -->
</body>
</html>