问:如何在多行中进行mysql查询搜索
我要进行脚本搜索的是:
if kat_preces_params.params_id is equal to 124 AND kat_preces_params.nosaukums is LIKE '%$make%',
AND if kat_preces_params.params_id is equal to 125 AND kat_preces_params.nosaukums is LIKE '%$model%'
AND IF kat_preces_params.params_id is equal to 126 AND kat_preces_params.nosaukums <=2009 AND kat_preces_params.nosaukums >=2000
我是如何尝试的(我知道这是错误的,因为它没有显示正确的值......):
PHP检查年份:
if($year == '2010 - ...'){
$gads = 'kat_preces_params.nosaukums <=2010';
}
elseif($year == '2000 - 2009'){
$gads = 'kat_preces_params.nosaukums <=2009 AND kat_preces_params.nosaukums >=2000';
}
elseif($year == '2000 - 2004'){
$gads = "kat_preces_params.nosaukums <=2004 AND kat_preces_params.nosaukums >= 2000";
}
elseif($year == '... - 1999'){
$gads = "kat_preces_params.nosaukums <=1991";
}
而且我有一个如下所示的 mysql 查询:
SELECT kat_prece.*, kat_preces_params.* FROM kat_prece, kat_preces_params WHERE pamat_kat_sad = '$cat_mod_id'
AND kat_prece.preces_id = kat_preces_params.preces_id
AND ((
kat_preces_params.params_id=124
AND kat_preces_params.nosaukums LIKE '%$make%'
)
|| (
kat_preces_params.params_id=125
AND kat_preces_params.nosaukums LIKE '%$model%'
)
AND kat_preces_params.params_id=126
AND $gads
)
$model
并且$make
是请求值
也许有可能INNER JOIN
或以某种方式(对内部连接一无所知)?
谢谢你!