The code below is causing the error in the title, and cant see why, could someone have a look for me please.
while($q=mysql_fetch_assoc($r)){ ?>
<input type="checkbox" name="countries[]" value="<?php echo $q['Id_Cntry']?>"onClick="javascript:checkRefresh()" <?php ((in_array($q['Id_Cntry'], $_REQUEST['countries'])) ? "checked=\"checked\" " : "")?> class="inline" /><?php echo $q['Nom_Cntry_DE']?> <?php
$query1 = mysql_query("select count(tbl_hotels.Id_Hot) as total1 FROM tbl_hotels LEFT JOIN tbl_countries ON (tbl_countries.Id_Cntry=tbl_hotels.IdCntry_Hot) LEFT JOIN tbl_hotname ON (tbl_hotname.Id_Hot=tbl_hotels.Id_Hot) LEFT JOIN tbl_amenities ON (tbl_amenities.Id_Ame=tbl_hotname.Id_Ame) WHERE (tbl_hotels.Act_Hot='1') AND (tbl_amenities.Id_Ame='806') AND (tbl_countries.Id_Cntry=". $q['Id_Cntry'] .") ORDER by tbl_hotels.Id_Hot");
$result1 = mysql_fetch_array($query1);
Hi yes I can see wha’ts happening, but not sure how to deal with it.
What I need is for this bit of code to only work when the checkbox is checked, as its displaying a row of countries, and they only come into play once they are checked.
Hi the good news is that has resolved an issue I had which was that after selection the checkbox wasn’t staying checked and was skewing the results, so thank you very much.
I checked the logs and the array value NULL still appears unless the checkbox is checked, so it still shows as an error in the logs, so is there a way around that, but am well happy that we got one of the other issues resolved, cheers
And if the checkbox isn’t selected I get this error -
Ägypten Notice: Undefined index: countries in \CSFFILES11\WEBSITES\live\new_checksafetyfirst\de\category_Result.php on line 447 NULL
But when the checkbox is selected I get -
Ägyptenarray(1) { [0]=> string(1) “9” }
So its fine when its checked, but not when it isn’t, and I know you have helped but I cant work out how to either give the array a value before its checked to not activate the error, or to somehow block the action that is causing the error, when the checkbox isn’t selected.
I have found the source if you like and have put an else statement to it, but what im not sure to do is what to put inside the else, to stop the error im getting when the checkbox isn’t checked.
if (is_array($_GET['countries'])) {
$countriesArray = array();
foreach($_GET['countries'] as $countries) {
$countriesArray[] = '\''.$countries.'\'';
}
$countriesData = implode(',', $countriesArray);
$sqlcountries = ' WHERE Id_Cntry IN ('. $countriesData .' )';
$sqlcountries2 = ' AND tbl_hotels.IdCntry_Hot IN ('. $countriesData .' )';
//$sqlregionName = 'WHERE Id_Rsrt IN ('. $regionData .' )';
//echo $sqlregionName;
//echo $regionData;
//echo $sqlcountries;
} else {
}
@multichild Be aware that the old mysql_* extension which you’re using is deprecated in version 5.5 of PHP (the current version) and is being removed from version 7 (the next version). You need migrate over to using either the mysqli_* extension or PDO
Thanks SpacePhoenix will add it to my list after this.
I seemed to make some progress yesterday and now need to apply the same sort of call to the checkbox area, as per my thread above, would you have any ideas?
You should give priority to replacing the mysql_ calls.
PHP 7 is due for release any day now and it introduces the ?? operator which will make solving your missing/empty field problem much simpler but it also no longer supports mysql_ calls