我是新手,目前在数据库上工作。我有一个如下模型:
/**
*
*I am editing a app which is done in version 1.3
* /app/models/get_provider.php
*/
function getListByCategory($gal_category_id,$gal_location_id,$package,$whether_list = false,$limit=999,$order_by = ""){
$conditions = array("GalProvider.status"=>1,"GalProvider.gal_category_id"=>$gal_category_id,"GalProvider.gal_location_id"=>$gal_location_id);
-------
-------
}
$package
变量是一个特殊的变量,具有以下条件:
if $package = 1,starting_package will be between 15000 to 30000
if $package = 2,starting_package will be between 30001 to 45000
if $package = 3,starting_package will be between 45001 to 60000
那么我将如何在where
变量中添加此$conditions
条件?
答案 0 :(得分:1)
这样的事情应该这样做:
<?php
function getListByCategory($gal_category_id,$gal_location_id,$package,$whether_list = false,$limit=999,$order_by = "") {
$conditions = array(
"GalProvider.status" => 1,
"GalProvider.gal_category_id" => $gal_category_id,
"GalProvider.gal_location_id" => $gal_location_id
);
switch ($package) {
case 1:
$start = 1500;
$end = 3000;
break;
case 2:
$start = 30001;
$end = 45000;
break;
case 3:
$start = 45001;
$end = 60000;
break;
}
$conditions['AND']['starting_package >='] = $start;
$conditions['AND']['starting_package <='] = $end;
-------
-------
}
因此,您需要确定范围的起点和终点,然后将其添加到查询中,并在“和”键中添加,以确保它们都被考虑在内。
的doco