SQL错误:使用`most`; SELECT`item_name`,SUM(`stock_invent`)AS`Total Items` FROM inventoryories GROUP BY`item_name

时间:2014-12-06 18:21:15

标签: mysql sql

我试图用SQL打印出列表项目总数。它适用于 phpmyadmin ,但不适用于Dreamweaver。我不知道我的SQL有什么问题。有人可以帮帮我吗?

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服务器版本,以便使用正确的语法   靠近'SELECT item_name,SUM(stock_invent)AS Total Items FROM   库存GROUP'在第1行

2 个答案:

答案 0 :(得分:0)

在phpMyAdmin(以及mysql的命令行工具)中使用use命令来选择要对其运行查询的数据库。在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`";

答案 1 :(得分: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);