我在從數據庫中提取數據後對其中的某些數據進行排序,但似乎在執行查詢時出現某種類型的錯誤。我爲我的php框架使用codeignither。Mysql按錯誤順序排列CI
以下是錯誤
錯誤編號:1064
你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本在1號線
爲了使用近 'ORDER BY 'ban_created_at' ASC' BY 'ban_created_at' ASC
文件名正確的語法手冊:../application/models /Infractions_model.php
行號:33
而相應的腳本(Infractions_Model)
function fetch_infractions($filter = null, $direction = null){
$query = "SELECT * FROM 'user_infractions', 'user'
WHERE 'user_infractions'.'user_id' = 'user'.'user_id'
AND 'user_infractions'.'ba_is_active' != '0'";
if ($filter != null) {
if ($filter == 'age') {
$filter ='ban_created_at';
switch ($direction) {
case 'ASC':
$dir = 'ASC';
break;
case 'DESC':
$dir = 'DESC';
break;
default:
$dir = 'ASC';
}
}
} else {
$dir = 'ASC';
}
$query = "ORDER BY 'ban_created_at' " . $dir;
/*Line 33*/ $result = $this->db->query($query, array($dir));
if ($result) {
return $result;
}else{
return false;
}
}
現在,我得到這個錯誤 錯誤編號正確的語法手冊:1064 你有一個錯誤在你的SQL語法中;檢查對應於你的MySQL服務器版本使用「」附近user_infractions',‘用戶’WHERE‘user_infractions’正確的語法手冊‘USER_ID’=‘用戶’。‘U’在行1 SELECT * FROM「 user_infractions','user'WHERE'user_infractions'。'user_id'='user'。'user_id'和'user_infractions'。'ba_is_active'!='0'ORDER BY ban_created_at ASC 文件名:../application/models/Infractions_model.php 行號:33 – David
請避免在你的sql查詢(表名和字段名)單引號。 像'select * form'user''不正確。正確的是來自用戶的'seelct *' –