Is this correct query I am trying........help..?

I want to match 1 value with 3 fields of database…

Here’s the information about it…please help…its important…


<?
                      $sql_c="select * from tblbusinessinfo where subcategory1 and subcategory2 and subcategory3 like '".$_REQUEST['get_searchword']."%' and city like '".$_REQUEST['city_search']."%'  order by business_id";
                      $result_c=mysql_query($sql_c);
                      $tot_record=mysql_num_rows($result_c);
                      
                        $record_per_page=20;
                        $scroll=4;
                        $zz=$_REQUEST['get_searchword'];
                        $xz=$_REQUEST['city_search'];
                        $page1=new page1(); 
                        
                                
                        $page1->set_page_data($_SERVER['PHP_SELF'],$tot_record,$zz,$xz,$record_per_page,$scroll,true,true,true);
                        $result_c = mysql_query($page1->get_limit_query($sql_c));
                        // For paging purpose 
                        if($_GET['page']=="" || !isset($_GET['page']) || $_GET['page']==0)
                            $sno=1;
                        else
                            $sno = ($record_per_page*$_GET['page'])+1;
                      
                      $sno_22 = 0;
                      if($tot_record > 0)
                      {
                      while($row_c=mysql_fetch_array($result_c))
                      { 
                        $sno_22++;
                        if($sno_22%3==1)
                        {
                      ?>

In result of above coding…its working for the city parameter…but not matching the keywords…Please help me to find out…where I mistook…

Your help would be highly appreciated.

Thanks


Try it this way:

 $sql_c="select * from tblbusinessinfo where subcategory1 like '".$_REQUEST['get_searchword']."%' OR subcategory2 like '".$_REQUEST['get_searchword']."%' OR subcategory3 like '".$_REQUEST['get_searchword']."%' and city like '".$_REQUEST['city_search']."%'  order by business_id"; 
                      $result_c=mysql_query($sql_c); 

make sure you parenthesize those ORs!!

SELECT * 
  FROM tblbusinessinfo 
 WHERE [COLOR="Red"][B]([/B][/COLOR] subcategory1 LIKE '".$_REQUEST['get_searchword']."&#37;' 
      OR subcategory2 LIKE '".$_REQUEST['get_searchword']."%' 
      OR subcategory3 LIKE '".$_REQUEST['get_searchword']."%' 
       [COLOR="red"][B])[/B][/COLOR]
   AND city like '".$_REQUEST['city_search']."%'  
ORDER 
    BY business_id

I find that it can help to indent the where clauses to help make things clearer.


SELECT
    * 
FROM
    tblbusinessinfo 
WHERE
    (
        subcategory1 LIKE '".$_REQUEST['get_searchword']."%' 
        OR subcategory2 LIKE '".$_REQUEST['get_searchword']."%' 
        OR subcategory3 LIKE '".$_REQUEST['get_searchword']."%' 
    )
    AND city like '".$_REQUEST['city_search']."%'  
ORDER BY
    business_id