tags:

views:

35

answers:

3

Hey

I'm trying to check sessionbasket before buying (and check if database store includes same units from session )

    foreach($_SESSION['cart'] AS $key => $qty){
  $sizes_id[] = $qty['units'];
 }

output from session:

Array(
    [0] => 1 (units)
    [1] => 5 (units)
)

lets assume that there is max 2 units in db, and 5 in session. I need to loop through the database and check if session is equal session output. if true, insert into db else, redirect front

A: 

I need to loop through the database and check if session is equal session output. if true, insert into db else, redirect front

It sounds like you know what you want to do.

So what are you asking? Do you want someone to code it up for you?

Anon.
i know how it works, but i cant't figure how to write it .
william
+1  A: 

Sort your units array in descending order.

Then fetch the units from the database in descending order. Should give you the same array. Here's a query similar to what you will need:

SELECT id, units FROM article_sets WHERE article_id=XXX ORDER BY units DESC
Franz
A: 

i found the solution.

        foreach ($_SESSION['cart'] AS $sizes_id => $qty){

            $in_stock = $db->GetScalar("SELECT s.units FROM products_sizes s 
                                        INNER JOIN products p ON p.product_id = s.product_id
                                        WHERE s.id = '$sizes_id'
            ");             
     }

This was the part i was searching for, and it works ->

     if ($in_stock == 0 || $_SESSION['cart'][$sizes_id]['units'] > $in_stock){
william