PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
require_once('common.php');
db_connect();
error_reporting(E_ALL ^ E_NOTICE);
foreach($_GET as $key=>$value) {
if ($value !== ''){
$chkbox_arr[]=' AND Amenities.'.$key."='y'";
}
}
//string together all elements in a single string
$sql_str = implode(" ", $chkbox_arr );
error_reporting(E_ALL);
$chkbox_arr = array();
foreach($_GET as $key=>$value) {
$chkbox_arr[]=' AND Amenities.'.$key."='y'";
}
//string together all elements in a single string
$sql_str = implode(" ", $chkbox_arr );
There is no need to check whether there are values contained within the check box, as it won't be passed in your post if it was not checked.
ye, i had to declare it to remove the error. not sure why. i always read that you didn't have to declare variables or arrays in php before they're used.
In your originally posted code, if $_GET was empty, $chkbox_arr would never exist by the time your call to implode() was run. With arrays, it is especially important to have them declared before reading them. While some of this importance is lesser now with register_globals off, it's still a valid and good practice to initialize your variables.