-1

这是错误必须在查询 3 或 4 中的整个代码。正如您所见,查询 3 只是获取信息来构建查询 4,它应该返回结果。

我的查询 1 和 2 工作正常,其中显示了正确的数据。

<?php
session_start();
//printf('<pre>%s</pre>', print_r($_SESSION, true));
require('includes/config.inc.php');
require('includes/session.php');

//WORKING
DB_Connect();
$query = "SELECT * FROM food_delivery_orders_items WHERE food_delivery_orders_items.type = 'product' AND food_delivery_orders_items.order_id=".$_SESSION['pdf_quote']['id']."";

$result = mysql_query( $query) or die(mysql_error());

while($row = mysql_fetch_array($result)) 
            {
         $hash = $row['hash'];
         $foreignid = $row['foreign_id'];
          $qty = $row['cnt'];                   
            }


$query2 = "SELECT * FROM food_delivery_products WHERE food_delivery_products.id = ".$foreignid."";

$result2 = mysql_query( $query2) or die(mysql_error());

while($row = mysql_fetch_array($result2)) 
            {
         $name = $row['name'];
         $description = $row['description'];                
            }



    //---------------------------------------------------------------------------------------------------------------

    $query3 = "SELECT * FROM food_delivery_orders_items WHERE food_delivery_orders_items.type = 'extra' AND food_delivery_orders_items.order_id=".$_SESSION['pdf_quote']['id']."";

$result3 = mysql_query( $query3)or die(mysql_error()) ;

while($row = mysql_fetch_array($result3)) 
            {

         $foreignidextra = $row['foreign_id'];  
         $qtyextra = $row['cnt'];           

            }


            $query4 = "SELECT * FROM food_delivery_extras WHERE food_delivery_extras.id = ".$foreignidextra."";

$result4 = mysql_query( $query4) or die(mysql_error());

while($row = mysql_fetch_array($result4)) 

            {
         $nameextra = $row['name'];

            }

    echo $nameextra;
    echo $qtyextra;

DB_Disconnect();





//$products = implode(", ",$_SESSION['pdf_quote']['product_arr']);;

//print $products
?>
4

2 回答 2

1

print $row; 如果要打印所有这些,则仅在循环内有效。否则它将只打印最后一个$row. 做了

while($row = mysql_fetch_array($result3)) 
{
    $foreignidextra = $row['foreign_id'];   
    $qtyextra = $row['cnt'];            
    print $row;
}
于 2013-10-16T01:18:58.877 回答
1

这是因为您在循环执行$row后 打印while

所以它只打印最终结果集

改用这样的东西:

$query3 = "SELECT * FROM food_delivery_orders_items WHERE food_delivery_orders_items.type = 'extra' AND food_delivery_orders_items.order_id=".$_SESSION['pdf_quote']['id']."";

$result3 = mysql_query( $query3) ;

while($row = mysql_fetch_array($result3)) 
{
    $foreignidextra = $row['foreign_id'];   
    $qtyextra = $row['cnt']; 
    print_r($row);           
}

你也可以使用var_dump($row);代替print_r($row);

$row这将在每次循环迭代时输出存储在数组中的所有值

于 2013-10-16T01:19:20.173 回答