PHP无法显示数据库中所有必需的数据

PHP无法显示数据库中所有必需的数据,php,mysql,database,Php,Mysql,Database,我正在努力创建一个工作良好的电子商务网站。 但是,当我尝试查看创建的订单时。 数据库中已经存在的记录,并且只显示特定顺序中的第一条记录 谢谢你的帮助 代码: 桌面外观的屏幕截图 您正在使用$Contents\u result,而该循环已在使用它。这将破坏外环 $oid = $row['order_id']; $Contents_Query = "SELECT * FROM order_contents WHERE order_id = '$oid' "; $Content

我正在努力创建一个工作良好的电子商务网站。 但是,当我尝试查看创建的订单时。 数据库中已经存在的记录,并且只显示特定顺序中的第一条记录

谢谢你的帮助

代码:

桌面外观的屏幕截图

您正在使用$Contents\u result,而该循环已在使用它。这将破坏外环

    $oid = $row['order_id'];
    $Contents_Query = "SELECT * FROM order_contents WHERE order_id = '$oid' ";
    $Contents_result = mysqli_query( $dbc, $Contents_Query) ;   

    while ( $content_row = mysqli_fetch_array( $Contents_result, MYSQLI_ASSOC ))
    {
        #TD stands for Table Data and adds a cell to the Table Row
        #The full stop is used as concatenation (to join two strings)
        #echo '<tr><td> <strong>' . $content_row['item_id'] .'</strong><br> </td>'. 
        # '<td> <strong>' . $content_row['quantity'] .'</strong><br> </td> </tr>';
        $iid =  $content_row['item_id'];
        $Contents_Query = "SELECT * FROM shop WHERE item_id = '$iid' ";
        $Contents_result2 = mysqli_query( $dbc, $Contents_Query) ;   
// error correction     ^
        echo '<td> <strong>Item ID</strong><br> </td>'. 
         '<td> <strong> Item Name </strong><br> </td></tr>';

        while ( $content_row = mysqli_fetch_array( $Contents_result2, MYSQLI_ASSOC )) {
// error correction  --------------------------------------------- ^
            #TD stands for Table Data and adds a cell to the Table Row
            #The full stop is used as concatenation (to join two strings)
            echo '<tr><td> <strong>' . $content_row['item_id'] .'</strong><br> </td>'. 
                 '<td> <strong>' . $content_row['item_name'] .'</strong><br> </td> </tr>';              


        } 

        #    '<td> <strong>' . $content_row['total'] .'</strong><br> </td>'.
        #    '<td> <strong>' . $content_row['Sent'] .'</strong><br> </td>'.
        #    '<td> <strong>' . $content_row['order_date'] .'</strong><br> </td>'.
        #    '</tr>';
    }

您可能在标题之前输出;错误报告和mysqli_error$dbc在查询中说了什么;你的录取记录有问题。过去的问题解决了吗?如果是这样,最好将它们标记为已解决。不会显示错误。一些合理的代码缩进将是一个好主意。它帮助我们阅读代码,更重要的是,它将帮助您为自己的利益调试代码。您可能会在几周/几个月内被要求修改此代码,最后您会感谢我。您正在使用$Contents\u result,而该循环已经在使用它。那会破坏外环非常感谢你,它现在可以按我的要求工作了。再次感谢:
    $oid = $row['order_id'];
    $Contents_Query = "SELECT * FROM order_contents WHERE order_id = '$oid' ";
    $Contents_result = mysqli_query( $dbc, $Contents_Query) ;   

    while ( $content_row = mysqli_fetch_array( $Contents_result, MYSQLI_ASSOC ))
    {
        #TD stands for Table Data and adds a cell to the Table Row
        #The full stop is used as concatenation (to join two strings)
        #echo '<tr><td> <strong>' . $content_row['item_id'] .'</strong><br> </td>'. 
        # '<td> <strong>' . $content_row['quantity'] .'</strong><br> </td> </tr>';
        $iid =  $content_row['item_id'];
        $Contents_Query = "SELECT * FROM shop WHERE item_id = '$iid' ";
        $Contents_result2 = mysqli_query( $dbc, $Contents_Query) ;   
// error correction     ^
        echo '<td> <strong>Item ID</strong><br> </td>'. 
         '<td> <strong> Item Name </strong><br> </td></tr>';

        while ( $content_row = mysqli_fetch_array( $Contents_result2, MYSQLI_ASSOC )) {
// error correction  --------------------------------------------- ^
            #TD stands for Table Data and adds a cell to the Table Row
            #The full stop is used as concatenation (to join two strings)
            echo '<tr><td> <strong>' . $content_row['item_id'] .'</strong><br> </td>'. 
                 '<td> <strong>' . $content_row['item_name'] .'</strong><br> </td> </tr>';              


        } 

        #    '<td> <strong>' . $content_row['total'] .'</strong><br> </td>'.
        #    '<td> <strong>' . $content_row['Sent'] .'</strong><br> </td>'.
        #    '<td> <strong>' . $content_row['order_date'] .'</strong><br> </td>'.
        #    '</tr>';
    }