gpt4 book ai didi

php - 在MySQL表中仅当字段不为空或不为 ' '时选择

转载 作者:行者123 更新时间:2023-11-30 22:41:12 26 4
gpt4 key购买 nike

我的大部分值都已填充,但 set_price 列几乎没有空白字段。我只想在 set_price 不为空或不是 '' 时选择。我正在使用 mysql,设置价格的数据类型是 set_price varchar(50) NOT NULL,

我的函数:

 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

最佳答案

希望这个工作!

$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;

关于php - 在MySQL表中仅当字段不为空或不为 ' '时选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31107083/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com