2015-06-29 28 views
1

我的大部分值被填充,但set_price列有少量空字段。我只想在set_price不爲空或不是''時才選擇。我使用MySQL和數據類型爲固定的價格設定的set_price VARCHAR(50)NOT NULL,在MySQL表中選擇只有當一個字段不爲空或''

MY功能:

function getAvilableServiceDetails($service_id,$select_from,$select_to,$select_weight,$dimesion_height,$dimesion_width,$dimesion_girth,$price_shorting) 
      { 
       global $objSmarty; 

     // echo $service_id."//".$select_from."//".$select_to."//".$select_weight."//".$dimesion_height."//".$dimesion_width."//".$dimesion_girth."//".$price_shorting; exit; 

       if($select_weight=='') 
        $select_weight=0; 

       if($dimesion_height!='') 
       $height_condition=" and dimesion_height>=".$dimesion_height; 
       else 
       $height_condition=""; 

       if($dimesion_width!='') 
       $width_condition=" and dimesion_width>=".$dimesion_width; 
       else 
       $width_condition=""; 

       if($dimesion_girth!='') 
       $girth_condition=" and dimesion_girth>=".$dimesion_girth; 
       else 
       $girth_condition=""; 



       //===================searching condition=========================// 
        if($_SESSION['package_search_by']!='') 
         $searching_condition=" and service_type='".$_SESSION['package_search_by']."'"; 
        else 
         $searching_condition="";  

       //=====================price shorting============================// 
       if($price_shorting!='') 
       { 
        if($price_shorting=='L_TO_H') 
         $order_by=" group by unique_id order by set_price ASC "; 
        else  
         $order_by=" group by unique_id order by set_price DESC "; 
       } 
       else 
       { 
        $order_by=" group by unique_id order by set_price ASC "; 
       } 

       if($select_from!='' && $select_to!='' && $service_id!='') 
       { 
        $select_query="select * from set_delivery_package_details where service_id='".$service_id."' and 
        dimesion_weight>=".$select_weight." and set_price IS NOT NULL and set_price<>'' and FIND_IN_SET ('".$select_from."',sel_countrys) and FIND_IN_SET ('".$select_to."',sel_countrys) and deleted='N' and status='Y' ".$searching_condition.$height_condition.$width_condition.$girth_condition.$order_by; 
        $this->dbh->Query($select_query); 
        if($this->dbh->num_rows>0) 
        { 
         $PackageData=$this->dbh->FetchAllResults($select_query); 
         $objSmarty->assign("PackageData", $PackageData); 
        } 
        else 
        { 
         $searching_error_message="Record Not Found"; 
         $objSmarty->assign("searching_error_message", $searching_error_message); 
        } 


       } 
       else 
       { 
        $searching_error_message="Record Not Found Please Search Again"; 
        $objSmarty->assign("searching_error_message", $searching_error_message); 
       } 
      } 

我使用該表:please click here

+0

你得到了什麼錯誤 –

+0

沒有錯誤,但仍然結果是即使在set_price爲空後仍然打印 –

+0

甚至沒有你的其他語句 –

回答

0

希望這項工作!

$select_query = 
    "SELECT * 
    FROM set_delivery_package_details 
    WHERE service_id='".$service_id."' 
     AND dimesion_weight>=".$select_weight." 
     AND (set_price != NULL 
      OR set_price != '' 
      OR set_price IS NOT NULL 
      OR set_price <> '') 
     AND FIND_IN_SET ('".$select_from."',sel_countrys) 
     AND FIND_IN_SET ('".$select_to."',sel_countrys) 
     AND deleted='N' 
     AND status='Y' " 
    .$searching_condition 
    .$height_condition 
    .$width_condition 
    .$girth_condition 
    .$order_by; 
+0

在這種情況下不起作用。 –

0

表達:

set_price != '' 

不計算爲真時set_priceNULL

我懷疑你可能不希望空格:

trim(set_price) <> '' 

您可以添加and set_price is not null如果你想要的,但是這是不必要的。

+0

不工作,對不起。 –

相關問題