Hi,

I did my foreach (for an advanced search) separately because I had difficulties in dealing with my checkboxes result. Thankfully, it works now but... I'm not sure how I can combine the two foreach into just one, to produce a single foreach loop... 😕

This is the first foreach...

$sql = "SELECT * FROM movie WHERE publish=1 AND ";

$counter = 0; //checks whether an sql statement is a following or a first

foreach($_POST as $key => $value){

  if($key == "search"){
	if(empty($value)){
	$keyword = "";
	}else{
	$keyword = $value;
	}
  }else if($key == "searchby"){
    if(empty($keyword)){
	}else{
	$sql .= "$value LIKE '%$keyword%'";
	$counter = $counter + 1;
	}
  }else if($key == "Release_date"){
    if(empty($value)){
	}else{
	if($counter > 0){
	$sql .= "AND (Release_date >='$value')";
	$counter = $counter + 1;
	}else{
	$sql .= "(Release_date >='$value')";
	$counter = $counter + 1;
	}
	}
  }else if($key == "Release_date2"){
    if(empty($value)){
	}else{
	if($counter > 0){
	$sql .= " AND (Release_date >='$date1') AND (Release_date <='$value') Order by Release_date ASC";
	$counter = $counter + 1;
	}else{
	$sql .= "(Release_date >='$date1') AND (Release_date <='$value') Order by Release_date ASC";
    }

This is another foreach...

if(!empty($_POST["rating"]))  {

$c=count($_POST["rating"])-1;
$q=0;
foreach($_POST["rating"] AS $keys)
{
    $in_id.="$keys";
    if($q==$c)
    break;
    else
    $in_id.=",";

    $q++;
}

$sql="SELECT * FROM movie WHERE rating IN ($in_id) ORDER BY rating ASC";
    Write a Reply...