1 頁 (共 1 頁)

ORDER BY FIELD not working

發表於 : 2016-11-02 23:33:11
yehlu
http://stackoverflow.com/questions/1156 ... or-message

代碼: 選擇全部

SELECT pts_name
FROM   products_tecspecs
WHERE  pts_id IN ( 5275, 21, 5276, 5277,
                   5278, 49, 5279 )
ORDER  BY FIELD(pts_id, 5275, 21, 5276, 5277, 5278, 49, 5279) 

ORDER BY FIELD(
FIELD 及 刮號中間不能有空白

Re: ORDER BY FIELD not working

發表於 : 2016-11-02 23:33:57
yehlu
ccs4 modify

代碼: 選擇全部

$query = str_replace("'","",$this->OptimizeSQL(CCBuildSQL($this->SQL, $this->Where, $this->Order)));//去掉'
        $query = substr($query,0,-10);//去掉 LIMIT
        $query .= " ORDER BY FIELD(student_no,".$_GET['s_class_student_no'].")";//加上依輸入資料排序
        echo $query;

        //$this->query($this->OptimizeSQL(CCBuildSQL($this->SQL, $this->Where, $this->Order)));
        $this->query($query);