订购时遇到问题.. 如果我将请求设置为s = 10或s11,则无效... 我尝试打印$ order请求,它工作,但它没有出现在$ sql =($ order)
if(isset($_GET['s']) AND $_GET['s']==10)
{
$order=' ORDER BY a.saskanojuma_nr ASC';
}
elseif(isset($_GET['s']) AND $_GET['s']==11)
{
$order=' ORDER BY a.saskanojuma_nr DESC';
}
else
{
$order=' ORDER by a.id desc';
}
$sql='SELECT a.projekta_id, a.saskanojuma_nr, a.datums, a.akcepta_nr, a.objekta_autors FROM '.$table_prefix.'_saskanojumi a LEFT JOIN '.$table_prefix.'_projekti b ON b.id=a.projekta_id LEFT JOIN '.$table_prefix.'_objekti c ON c.id=b.objekta_id LEFT JOIN '.$table_prefix.'_kadastri d ON d.objekta_id=c.id LEFT JOIN '.$table_prefix.'_ipasnieki e ON e.objekta_id=c.id '.$query.' AND a.buvvaldes_id='.$_SESSION['buvvaldes_id'].' AND a.dzests=0 GROUP BY a.id '.$order.' ';
$thiss=$GLOBALS['db']->query($sql);
答案 0 :(得分:1)
此处显示的代码似乎正确无误。也许问题出在其他地方。
一步一步 banchmark 您的代码,并尝试找出错误的位置。
答案 1 :(得分:0)
尝试使用PHP switch/case
语法:
switch ($_GET['s']) {
case 10:
$order=' ORDER BY a.saskanojuma_nr ASC';
break;
case 11:
$order=' ORDER BY a.saskanojuma_nr DESC';
break;
default:
$order=' ORDER by a.id desc';
break;
}
如果$_GET['s']
不是10或11,$order
变量的值将来自'default
'语句,即ORDER by a.id desc