2014-12-06 66 views
0

我試圖打印出SQL列表項目總數。它在phpmyadmin上運行良好,但不能在Dreamweaver中運行。我不知道我的SQL有什麼問題。任何人都可以幫助我?SQL錯誤:USE`most`; SELECT'item_name`,SUM(`stock_invent`)AS`Total Items` FROM inventory GROUP BY`item_name

mysql_select_db($database_dbcon, $dbcon); 

$query_Recordset1 = "USE `most`; SELECT `item_name`, SUM(`stock_invent`) AS `Total Items` FROM inventories GROUP BY `item_name`"; 

$Recordset1 = mysql_query($query_Recordset1, $dbcon) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 

我得到了這樣的消息:

您的SQL語法錯誤;檢查手冊中 對應於你的MySQL服務器版本正確的語法使用 近「選擇item_name,SUM(stock_invent)AS Total Items FROM 庫存GROUP」在1號線

+0

嘗試使用,而不是爲列別名反引號單引號。 – AdamMc331 2014-12-06 18:25:01

+0

我不熟悉這種多查詢語法。 – Strawberry 2014-12-06 18:50:37

回答

0

use命令在phpMyAdmin使用(以及在mysql的命令行工具中)選擇要運行查詢的數據庫。在PHP中,你不應該需要它 - 這就是mysql_select_db是:

mysql_select_db('most', $dbcon); 

$query_Recordset1 = "SELECT `item_name`, SUM(`stock_invent`) AS `Total Items` FROM inventories GROUP BY `item_name`"; 
0
mysql_select_db('most', $dbcon); 

$query_Recordset1 = "SELECT item_name, SUM(stock_invent) AS Total Items FROM inventories GROUP BY item_name "; 

$Recordset1 = mysql_query($query_Recordset1, $dbcon) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1);