Click here to Skip to main content
15,881,561 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I feel like i almost got the solution but I'm just not there yet maybe some of you can help me. I have this array where I put id's in. what I want to do is show in winkelmandje (a.k.a shopping cart) the items that are equal to the id. how do I do this? I just can't figure it out??

This is my code
PHP
<pre>session_start();
error_reporting(E_ALL);
ini_set('display_errrors', '1');
// session_destroy();
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
        <meta name="description" content="" />
        <meta name="author" content="" />
        <title>Cart</title>
        <!-- Favicon-->
        <link rel="icon" type="image/x-icon" href="assets/favicon.ico" />
        <!-- Bootstrap icons-->
        <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.5.0/font/bootstrap-icons.css" rel="stylesheet" />
        <!-- Core theme CSS (includes Bootstrap)-->
        <link href="css/styles.css" rel="stylesheet" />
        <link href="css/stylecart.css" rel="stylesheet" />
        <script src="js/scripts.js" async></script>

    </head>
    <style>
    body {
        font-size: 20px;
    }

    </style>
<body>
<a class="back" href="index.php"> </a>
<?php
include "config.php";
    print_r($_SESSION['basket']);
    
    
    // oke het is neit geweldig maar het laat iets s
        ?>
        <div class="text-center" style="font-size: 100px;">🛍</div>
        <h2 class="text-center">Winkelmandje</h2><br>
        <section class="container content-section">
            <!-- <h2 class="section-header">CART</h2> -->
            <div class="cart-row">
                ITEM
                PRICE
                <!-- QUANTITY -->
            </div> 
            <?php
            
               $broodjes_ID = $_GET['broodjes_ID'];
                //onthouden van vorige get request
                $count = count($_SESSION['basket']); // count basket puts 3 times the same item in the shopping cart
                //echo $count;
                if($count > 0){
                    
                    for($i = 0; $i<$count; $i++){
                        // var_dump($_SESSION['basket']);
                        foreach($_SESSION['basket'] as $key => $value){
                            $sum = 0;
                            echo "Key = $key; value = $value; <br>";
                            
                        } break;?> <br />
                        <?php                           
                            
                        }
                        
                        
                    }
                ?>
                    <div class="cart-total">
                        <?php echo $sum;?>
                    </div>
            

                <div class="cart-total">
                    ^__strong class="cart-total-title">Total
                     € 0
                </div>
            



            <div class="text-center">
                <button class="btn btn-outline-primary"  type="button"><a href="bestellen.php">PURCHASE</a></button>
            </div>
        </section>
</body>

idk how to show a picture here but this is the results that I'm getting
Key = 0; value = 1;
Key = 1; value = 1;
Key = 2; value = 1;
Key = 3; value = 1;
Key = 4; value = 2;
Key = 5; value = 2;
Key = 6; value = 1;
Key = 7; value = 1;
Key = 8; value = 31;
Key = 9; value = 31;
Key = 10; value = 31;
Key = 11; value = 1;
Key = 12; value = 2;
Key = 13; value = 28;
Key = 14; value = 2;
Key = 15; value = 30;
Key = 16; value = 30;
Key = 17; value = 1;
Key = 18; value = 2;
Key = 19; value = 30;
Key = 20; value = 30;
Key = 21; value = 1;
Key = 22; value = 1;
Key = 23; value = 30;
Key = 24; value = 2;
Key = 25; value = 1;

so value = id
what I want to do is use the id from the array and show the items in the shopping cart based on the id that is found within the array. how do I do this??

What I have tried:

tried looking up online didn't found anything. it just shows it the way I have it right now
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900