0
我在維護一箇舊的網站,它在mysql查詢上拋出一些sql錯誤。錯誤如下...嵌套查詢的SQL語法錯誤
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 'OR syprc_serial IN (SELECT b.syprc_serial FROM syproductcategories.b WHERE b.syp' at line 1
我懷疑這是與我的嵌套選擇的語法,但我沒有成功地解決這個問題呢!任何人都得到了一些見解
$query = "SELECT syprc_serial, syprd_serial, sypcd_description, sypdd_title, sypdd_shortdescription, sypdd_longdescription, sypdd_primarypackage, sypdd_owner, syprd_image01, syprc_subcategoryof ".
"FROM syproductcategories, syproductcategoriesdescription, syproducts, syproductsdescription ".
"WHERE syprc_serial = sypcd_productcategoryserial ".
"AND syprd_categoryserial = syprc_serial ".
"AND sypdd_languagecode = '". $_SESSION['language']."' ".
"AND sypcd_languagecode = '". $_SESSION['language']."' ".
"AND syprd_serial = sypdd_productserial ".
"AND syprc_companyserial = '" . $_SESSION['company'] ."' ".
"AND syprd_companyserial = '" . $_SESSION['company'] ."' ".
"AND syprd_active = 1 ".
"AND (syprc_serial = $syprc_serial ".
"OR syprc_serial IN (SELECT b.syprc_serial FROM syproductcategories b WHERE b.syprc_subcategoryof = $syprc_serial) ".
"OR syprc_subcategoryof IN (SELECT b.syprc_serial FROM syproductcategories b WHERE b.syprc_subcategoryof = $syprc_serial) ".
") ".
"ORDER BY syprc_serial, sypdd_title, syprd_serial";
如果您只是在該行後面打印您的查詢,您應該看到它的外觀以及檢查錯誤的方式。 – Olli 2014-09-19 09:59:01
@TheChaos如果沒有真正的查詢,我們只能推測'$ syprc_serial'計算結果爲空字符串... – VMai 2014-09-19 10:05:14
你在哪裏定義'b'?錯誤消息和查詢看起來不一樣:'FROM syproductcategories b'沒有點... – 2014-09-19 10:07:33