0

My cart checkout submits the chosen products into a 'my orders page' where the products are separated into different rows and individual payments with the same invoice number. How can I combine these rows into one with total price and total quantity and one payment method for all three products?

Screenshot of cart


<div class="table-responsive">

    <table class="table table-bordered table-hover">

        <thead>

            <tr>

                <th> ON: </th>
                <th> Due Amount: </th>
                <th> Invoice No: </th>
                <th> Qty: </th>
                <th> Size: </th>
                <th> Order Date: </th>
                <th> Paid / Unpaid: </th>
                <th> Status: </th>

            </tr>

        </thead>

        <tbody>


            <?php 

                $customer_session = $_SESSION['customer_email'];

                $get_customer = "select * from customers where customer_email='$customer_session'";

                $run_customer = mysqli_query($con,$get_customer);

                $row_customer = mysqli_fetch_array($run_customer);

                $customer_id = $row_customer['customer_id'];

                $get_orders = "select * from customer_orders where customer_id='$customer_id'";

                $run_orders = mysqli_query($con,$get_orders);

                $i = 0;

                while($row_orders = mysqli_fetch_array($run_orders)){

                    $order_id = $row_orders['order_id'];

                    $due_amount = $row_orders['due_amount'];

                    $invoice_no = $row_orders['invoice_no'];

                    $qty = $row_orders['qty'];

                    $size = $row_orders['size'];

                    $order_date = substr($row_orders['order_date'],0,11);

                    $order_status = $row_orders['order_status'];

                    $i++;

                    if($order_status == 'Pending'){
                    
                        $order_status = 'Unpaid';
                        
                    }else{
                        
                        $order_status = 'Paid';
                        
                    }

            ?>

            <tr>

                <th> <?php echo $i; ?> </th>
                <td> AED<?php echo $due_amount; ?> </td>
                <td> <?php echo $invoice_no; ?> </td>
                <td> <?php echo $qty; ?> </td>
                <td> <?php echo $size; ?> </td>
                <td> <?php echo $order_date; ?> </td>
                <td> <?php echo $order_status; ?> </td>

                <td>
                    <a href="confirm.php?order_id=<?php echo $order_id; ?>" target="_blank" class="btn btn-primary btn-sm"> Confirm Payment </a>
                </td>

            </tr>

            <?php } ?>

        </tbody>

    </table>


</div>```
Roman
  • 2,530
  • 2
  • 27
  • 50
Sean Cruz
  • 9
  • 1
  • you need to share customer_orders table definition and maybe example data for a solution i think – Ali Fidanli Sep 21 '21 at 05:39
  • 3
    Don't ever put variables in to a query string that way! you are wide open to SQL injection. use prepared statements. – Gert B. Sep 21 '21 at 06:20
  • **Warning:** You are wide open to [SQL Injections](https://php.net/manual/en/security.database.sql-injection.php) and should use parameterized **prepared statements** instead of manually building your queries. They are provided by [PDO](https://php.net/manual/pdo.prepared-statements.php) or by [MySQLi](https://php.net/manual/mysqli.quickstart.prepared-statements.php). Never trust any kind of input! Even when your queries are executed only by trusted users, [you are still in risk of corrupting your data](http://bobby-tables.com/). [Escaping is not enough!](https://stackoverflow.com/q/5741187) – Dharman Sep 21 '21 at 11:20

0 Answers0