Jump to content

Combine search queries into 1 search post


FutonGuy

Recommended Posts

Hi

 

does anyone know how to work on a combination of search queries of 2 or more different fields to narrow down the search option?

 

Scenario:

dev number: [free text-wildcard will be use]

site : [option-drop down list]

board number: [free text-wildcard will be use]

 

[sEARCH BUTTON]

 

User can search by either one of the options or all of the option to narrow down the search queries.

here's the code i have. Hopefully someone can help me with my queries..

 

 $val_d = $_POST['device_search'];
$val_sub = $_POST['subconsite'];
echo "$val_d";  echo "<br>"; echo "$val_sub";

if (trim($val_d) != '' or  trim($val_sub) != ''){ 

    $sql = "select * from wsdevice"; 
    if (trim($val_d) != ''){  
        $sql .= " where wsdevice_num like '%$val_d%'  ";  //'%" . trim($val_d) . "%' 
        $where = true; 
    } 
    if (trim($val_sub) != ''){ 
        if (!$where){  
            $sql .= " where subcon_site like '%$val_sub%'  ";  // '%" . trim($val_sub) . "%'
        } 
        else { 
             $sql = str_replace("where ", "where (", $sql); 
             $sql .= " and subcon_site like '%$val_sub%') or (wsdevice_num like '%$val_d%' or subcon_site like '%$val_sub%')";  
        } //   '%" . trim($val_sub) . "%' 	'%" . trim($val_sub) . "%'	 '%" . trim($val_d) . "%'
} 
else { 
    die("NO SEARCH TERMS"); 
} 

$results = mysql_query($sql) or die (mysql_error()); 

$numrows = mysql_num_rows($results);  

// This is where i output my results
include "WSsearchtable.php";

 

Cheers..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.