2014-12-06 73 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);