Skip to content
Advertisement

php loop problems

noob problem: i have some issues with a loop in php…here is the code (i used the same methodology for other pages and it works); the code it is supposed to display the names of the products from a order, it works, but it is not showing the very first product , i don’t know why :

<?php $i=1; while($row_selectOrderItems = mysqli_fetch_array($result_selectOrderItems)){ ?>
        <tr>
            <td> <?php echo $i; ?> </td>
            <td> <?php echo $row_selectOrderItems['pro_name']; ?> </td>
            <td> <?php echo $row_selectOrderItems['pro_price']; ?> </td>
            <td> <?php echo $row_selectOrderItems['q']; ?> </td>
            <td> <?php echo $row_selectOrderItems['q']*$row_selectOrderItems['pro_price']; ?> </td>
        </tr>
        <?php $i++; } ?> 

and here is the code where i used mysqli_fetch_array before the loop

        $query_selectOrderItems = "SELECT *,order_items.quantity AS q  FROM orders,order_items,products WHERE order_items.order_id='$order_id' AND order_items.pro_id=products.pro_id AND order_items.order_id=orders.order_id";
        $result_selectOrderItems = mysqli_query($con,$query_selectOrderItems);                  
        $row_selectOrderItems=mysqli_fetch_array($result_selectOrderItems);

Does anyone have any idea how should i modify this code? Thank you!

Advertisement

Answer

$row_selectOrderItems=mysqli_fetch_array($result_selectOrderItems);

remove this line, so that, it will not read the 1st result at starting. Now, when you use it in the while loop, it reads the first line

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement