hye to all and gud day.. i'm stuck with this page and yet i couldnt find any solution on my advanced search page.

In this page, i have a lot of search criterias which includes text fields, comboboxes and list boxes. Keywords searched thru Text fields and comboboxes (logically with one option selected) gave the right results BUT, the list boxes where user can select multiple options gave me nothing, no result (i wonder why the sql query doesnt work at all??).. 😢

can anybody please... help me in solving this problem? it has made me stuck for weeks~~~

These codes are in my Advance Search Page:

// Get action
$sAction = @$HTTP_POST_VARS["a_search"];
switch ($sAction)
{
	case "S": // Get Search Criteria

// Build search string for advanced search, remove blank field
$sSrchStr = "";

// Field ReligionName
$x_ReligionName = @$HTTP_POST_VARS["x_ReligionName"];
$z_ReligionName = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_POST_VARS["z_ReligionName"][0]) : @$HTTP_POST_VARS["z_ReligionName"][0]; 
if ($x_ReligionName <> "") {
	$sSrchFld = $x_ReligionName;
	$sSrchWrk = "x_ReligionName=" . urlencode($sSrchFld);
	$sSrchWrk .= "&z_ReligionName=" . urlencode($z_ReligionName);
} else {
	$sSrchWrk = "";
}
if ($sSrchWrk <> "") {
	if ($sSrchStr == "") {
		$sSrchStr = $sSrchWrk;
	} else {
		$sSrchStr .= "&" . $sSrchWrk;
	}
}

if ($sSrchStr <> "") {
	ob_end_clean();
	header("Location: ViewSearchResultCus.php" . "?" . $sSrchStr);
	exit();
}
}

While these codes are in my result list page:

// Open connection to the database
$conn = phpmkr_db_connect(HOST, USER, PASS,DB);

// Handle Reset Command
ResetCmd();

// Get Search Criteria for Advanced Search
SetUpAdvancedSearch();

// Build Search Criteria
if ($sSrchAdvanced != "") {
	$sSrchWhere = $sSrchAdvanced; // Advanced Search
}
elseif ($sSrchBasic != "") {
	$sSrchWhere = $sSrchBasic; // Basic Search
}

// Save Search Criteria
if ($sSrchWhere != "") {
	$HTTP_SESSION_VARS["ViewSearchResult_searchwhere"] = $sSrchWhere;

// Reset start record counter (new search)
$nStartRec = 1;
$HTTP_SESSION_VARS["ViewSearchResult_REC"] = $nStartRec;
}
else
{
	$sSrchWhere = @$HTTP_SESSION_VARS["ViewSearchResult_searchwhere"];
}

// Build WHERE condition
$sDbWhere = "";
if ($sDbWhereMaster != "") {
	$sDbWhere .= "(" . $sDbWhereMaster . ") AND ";
}
if ($sSrchWhere != "") {
	$sDbWhere .= "(" . $sSrchWhere . ") AND ";
}
if (strlen($sDbWhere) > 5) {
	$sDbWhere = substr($sDbWhere, 0, strlen($sDbWhere)-5); // Trim rightmost AND
}


//-------------------------------------------------------------------------------
// Function SetUpAdvancedSearch
// - Set up Advanced Search parameter based on querystring parameters from Advanced Search Page
// - Variables setup: sSrchAdvanced

function SetUpAdvancedSearch()
{
	global $HTTP_GET_VARS;
	global $sSrchAdvanced;

// Field ReligionName
$x_ReligionName = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["x_ReligionName"]) : @$HTTP_GET_VARS["x_ReligionName"];
   $arrFldOpr = "";
   $z_ReligionName = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_GET_VARS["z_ReligionName"]) : @$HTTP_GET_VARS["z_ReligionName"];
   $arrFldOpr = split(",",$z_ReligionName);
   if ($x_ReligionName <> "") {
      $sSrchAdvanced .= "customer.ReligionName "; // Add field
      $sSrchAdvanced .= @$arrFldOpr[0] . " "; // Add operator
          if (count($arrFldOpr) >= 1) {
	$sSrchAdvanced .= @$arrFldOpr[1]; // Add search prefix
          }
         $sSrchAdvanced .= (!get_magic_quotes_gpc()) ? addslashes($x_ReligionName) : $x_ReligionName; // Add input parameter
         if (count($arrFldOpr) >=2) {
	$sSrchAdvanced .= @$arrFldOpr[2]; // Add search suffix
         }
	$sSrchAdvanced .= " AND ";
  }
}

I just pasted few lines of codes that i think is relevant. Overview of my Advance page is: I have a listbox of Religion Name, where user can select few options which SHUD give results accordingly BUT apparently it's not.

If any one wants to see the full code, do tell me.. I really appreciate if anybody could give me any advice on this.. Thank you a lot in advance..

:glare: tired wif codes already~ videxx

    Which variable holds the name of your multiple select?

      Owh... Sorry bout that.. Ii've noticed that i forgot to paste the codes - the one that holds the variable. And here it goes:

      $x_ReligionNameList = "<select name=\"x_ReligionName[]\" multiple>";
      $sSqlWrk = "SELECT `ReligionName` FROM `religion`";
      $rswrk = phpmkr_query($sSqlWrk,$conn) or die("Failed to execute query" . phpmkr_error() . ' SQL:' . $sSqlWrk);
      if ($rswrk) {
      	$rowcntwrk = 0;
      	while ($datawrk = phpmkr_fetch_array($rswrk)) {
      		$ar_x_ReligionName= explode(",", @$x_ReligionName);
      		$x_ReligionNameList .= "<option value=\"" . htmlspecialchars($datawrk[0]) . "\"";
      		foreach ($ar_x_ReligionName as $cnt_x_ReligionName) {
      			if ($datawrk["ReligionName"] == trim($cnt_x_ReligionName)) {
      				$x_ReligionNameList .= "' selected";
      				break;
      			}
      		}
      		$x_ReligionNameList .= ">" . $datawrk["ReligionName"] . "</option>";
      		$rowcntwrk++;
      	}
      }
      @phpmkr_free_result($rswrk);
      $x_ReligionNameList .= "</select>";
      echo $x_ReligionNameList;
      

      I found out that the value selected werent passed into the URL code.. (that's how i know why the search doesnt give me any result).

      I have been modifying my codes.... when i drop the "[]" in \"x_ReligionName[]\" -> turns out, it only search for the last options i've selected... say i search for Christian, Buddha and Islam, the search result is only for Islam.. huhu... It makes me think the array (ar_x_ReligionName) is not working......

      then... i changed these codes (these are in my Advanced Search page, in early part : Get Action - $sAction)

      	
      // Field ReligionName
      $x_ReligionName = @$HTTP_POST_VARS["x_ReligionName"];
      

      into this....

      	
      // Field ReligionName
      $x_ReligionName = (get_magic_quotes_gpc()) ? stripslashes(@$HTTP_POST_VARS["x_ReligionName"][0]) : @$HTTP_POST_VARS["x_ReligionName"][0];
      

      turns out, it gives me the right result.. BUT, sometimes it's not.. urghh.. i know this is not the right way to solve my problem.. but i'm on the top of my head, cant think of any better solution, thus i'm doing try and error method... hope i will find any luck~

      huhu... HELPP~ 🙁 Bored In The Office :: videxx

        waaaa... 🙁 and why do i receive this fatal error again and again??

        Fatal error: Cannot use [] for reading in c:\program files\easyphp1-7\www\viewsearchcustomer.php on line 191

        I have made changs wif my codes as i told in the previous post.. might made my pc hang.. But i changed back to the origin, the way it suppose to be before i marked up anythin..

        Weirdly, i still got this msg.. anybody know how solve this fatal error? this is not even close to solve my problem.. :glare:

        cryin more and more... videxx

          As far as I know, the 1st item in the multiple select array does not hold the value of the 1st option - contrary to normal behaviours. So try starting with ["x_ReligionName"][1] instead.

          Nico

            As far as I know, the 1st item in the multiple select array does not hold the value of the 1st option - contrary to normal behaviours. So try starting with ["x_ReligionName"][1] instead.

            The fatal error has been solved~ thank god..

            I found out that ["x_ReligionName"][0] only return one variable of the array. say i select Buddha Christian and Islam, it will return the first char of the last selected option : Islam which is I, and append it in the URL.
            stil... the concept of the selected array is not working..

            thanx for your concern nico..

            🙁 Tired thinkin already maah..

              Write a Reply...