It should so long as your values are unique.
You could put the following line in a foreach as you wrrite each checkbox (the value 2 will obviously come from a variable, and you’d need to use that variable in all three places in the below line)
OK thats new stuff for me, so are you saying that when im creating the checkboxes for the regions to display according to the country ID, that will be inside as below:
MMM, no thats not right is it, can you see where I’m trying to get my head around it. Sorry cpradio, once again you thankfully joined in to help and the level rocketed by ten fold, and left me behind a little. Sorry.
Ok thanks, I hadn’t started doing it dynamically yet, but will set it out now, its pretty basic at this point to be honest, as the user chooses the country before coming to this page and thus it has an ID, so basically the regions will then be chosen according to that ID as below.
<form name="form1">
<?php
$r=mysql_query("select * from tbl_contnreg where (Id_Cntry='1')");
while($q=mysql_fetch_assoc($r)){ ?>
<input type="checkbox" name="check[]" value="<?=$q['Id_Rsrt']?>" onClick="javascript:checkRefresh()"/><?=$q['Id_Rsrt']?>
<? } ?>
</form>
There will be around 4-5 of these sections in the end, one for regions, one for star rating, one for ammenities and another for groups as in hotel groups, might be more but dont think so.
So the idea is after the page loads once the country is selected they see all the hotels from that country, then they can check checkboxes to get a more specific result, and each time they check a box, the page refreshes and the display changes.
I havent started on the other bit yet, as I needed to draw the names out of the database of the regions rather than the id’s to show, so I used the code below, which works, but it only seems to draw out a couple of the names of the regions not all of them.
Whilst looking at another area I’m also looking at how to get the array set properly to use it when selecting from the database, and I have below sort of working, but its bringing back the results and also it seems to be doubling up, and doing some strange things.
There something not quite right with it.
if (is_array($_GET['regions'])) {
foreach($_GET['regions'] as $regions) {
$regionsArray[] = '\\''.$regions.'\\'';
//echo $regions;
$ids = implode(',', $regionsArray);
echo $ids;
}
}
You can see the array in the dev area building below, and the added values in the array
I’m moving through this a bit every day now, and im now trying to tie things up in the select from database operation, but the code below is now not working, when the simpler version was.
$sql.= "SELECT * FROM tbl_hotels " . $sqlregion . " ";
$sql.= " order by Id_Hot";
while($q=mysql_fetch_assoc($sql)){ ?>
<p><?=$q['Nom_Hot']?></p>
The simpler version
$sql = mysql_query("SELECT * FROM tbl_hotels " . $sqlregion . " order by Id_Hot");
while($q=mysql_fetch_assoc($sql)){ ?>
<p><?=$q['Nom_Hot']?></p>
Be aware of what is in your foreach! (see comments below)
if (is_array($_GET['regions'])) {
$regionsArray = array();
foreach($_GET['regions'] as $regions) {
$regionsArray[] = '\\''.$regions.'\\'';
$regionData = implode(',', $regionsArray); // should be outside your foreach
$sqlregion = 'WHERE IdRsrt_Hot IN ('. $regionData .' )'; // should be outside your foreach
}
//echo $regionData;
//echo $sqlregion;
}
Call mysql_query; mysql_fetch_assoc only works with a mysql_query result, you never called mysql_query passing in your $sql…
$sql.= " select * from tbl_hotels ";
$sql.= " " .$sqlregion . "";
$sql.= " order by Id_Hot";
while($q=mysql_fetch_assoc($sql)){ ?>
<p><?=$q['Nom_Hot']?></p>
$sql.="select * from tbl_hotels ";
$sql.= "" .$sqlregion . "";
$sql.= " order by Id_Hot";
while($q=mysql_fetch_assoc(mysql_query($sql))){ // place mysql_query here
?>
<p><?=$q['Nom_Hot']?></p>