我试图用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
)ASTotal Items
FROM 库存GROUP'在第1行
答案 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);