2015-07-13 32 views
-2

完全錯誤:你在你的SQL語法錯誤,請檢查您的MySQL版本

Warning: odbc_exec(): SQL error: [MySQL][ODBC 5.3(w) Driver][mysqld-5.6.24]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 ID,category,Image1 FROM 3dprints WHERE category='model_making' ORDER' at line 1, SQL state 37000 in SQLExecDirect.

public function get_max_category($category){ 
    $query="SELECT TOP 1 ID,category,Image1 
      FROM ".$this->tblname." WHERE category='".$category."' 
      ORDER BY Date_of_creation DESC"; 
    $exec=odbc_exec($this->cnx,$query); 
    $id=odbc_result($exec,'ID'); 
    $category=odbc_result($exec,'category'); 
    $img1=odbc_result($exec,'Image1'); 
    return array($id,$category,$img1); 
} 

public function get_category(){ 
    $query="SELECT DISTINCT(category) FROM ".$this->tblname; 
    $exec=odbc_exec($this->cnx,$query); 
    while($row=odbc_fetch_row($exec)){ 
     $categories[]=odbc_result($exec,'category'); 
    } 
    return $categories; 
} 

回答

3

刪除TOP 1並添加查詢LIMIT 1

更改以下

$query="SELECT TOP 1 ID,category,Image1 
      FROM ".$this->tblname." WHERE category='".$category."' 
      ORDER BY Date_of_creation DESC"; 

TO

$query="SELECT ID,category,Image1 
       FROM ".$this->tblname." WHERE category='".$category."' 
       ORDER BY Date_of_creation DESC LIMIT 1"; 
+0

感謝它的工作。無論如何,我認爲我的問題是我使用舊的語法。感謝sadikhasan, –

相關問題