我有以下代码。它工作但是因为我将我的服务器更新到最后一个php版本,并且因为不推荐使用mysql_fetch_array,所以代码对我不起作用,我很难找到解决方案。欢迎任何帮助。
我有两列有数量和价格的列。我想总结所有件x价格,以找出我库存的产品总量。
$all_products_sumquery_raw = mysql_query(
"SELECT SUM(products_quantity * products_price_sorter) AS grand_total
FROM products WHERE products_quantity > 0"
);
$test1 = mysql_fetch_array($all_products_sumquery_raw);
echo '<h2>Total: <span class="totalUred">' .
number_format($test1[0], 2, ',', ' ') .
'</span>$.</h2>';
答案 0 :(得分:0)
使用mysqli让它再次运行:
$link = mysqli_connect("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT SUM(products_quantity * products_price_sorter) AS grand_total FROM products WHERE products_quantity > '0'";
$all_products_sumquery_raw = mysqli_query($link, $query);
/* associative and numeric array */
$test1 = mysqli_fetch_array($all_products_sumquery_raw, MYSQLI_BOTH);
echo '<h2>Total: <span class="totalUred">' .
number_format($test1[0], 2, ',', ' ') .
'</span>$.</h2>';