我遇到的情况是mysql_query()函数被输入mysql_fetch_array()函数被解释为布尔值而不是结果。
以下代码使用Using an SQL result in a foreach loop作为执行foreach循环的编码示例。代码可能存在多个问题,因为我的当前问题发生在foreach循环之前。
$results=mysql_query("SELECT * FROM order_details WHERE orderid = $orderid");
print "SELECT * FROM order_details WHERE orderid = $orderid";
$productid;
$quantity;
$price;
$resultset = array();
while ($row = mysql_fetch_arraY($results)) {
$resultset[] = $row;
}
foreach ($resultset as $result)
{
$productid = $result['productid'];
$quantity = $result['quantity'];
$price = $result['price'];
print "<br />$productid, $quantity, $price";
};
答案 0 :(得分:0)
答案 1 :(得分:0)
for($i=0;$i<$max;$i++) {
$pid=$_SESSION['cart'][$i]['productid'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($pid);
$pname;
$row = mysql_fetch_assoc(mysql_query("SELECT name\n"
. "FROM `products` \n"
. "WHERE SERIAL =$pid\n"
. "LIMIT 1"));
$pname = $row['name'];
print "<br />Product Name: $pname, Quantity: $q, Price: $price";
}