mysql_fetch_array()面临的挑战

时间:2013-12-04 23:19:12

标签: php mysql arrays foreach

我遇到的情况是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";
    };

2 个答案:

答案 0 :(得分:0)

如果一切正常,请将$orderid更改为'$orderid'。 一个重要的注意事项,尝试越过mysqliPDO而不是mysql。

答案 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";
    }
相关问题