I have a products table in mySQL database and the idea of this particular
script is that it recieves a product_id via POST, adds it to the list of
product id's and then displays all the products in the list (as a shopping
cart). It must then reset the session variable with the new list.
I'm also using the PHP-LIB template class for code seperation.
The problem I'm having is that the "foreach" loop isn't recognising the
array as an array (and even if I test it with is_array() it tells me it's
not an array) even though I have at the very least initialised it as an
empty array.
Can anyone help me with this problem as it is the only sticking point I've
come against on this site. Thanks in advance.
Lee Conlin
##### Begin Code #####
session_start();
$products_in_basket = array();
//
// Get current basket
//
if(isset($_SESSION['products_in_basket'])) {
$products_in_basket = explode(',', $_SESSION['products_in_basket']);
}
function show_page() {
GLOBAL $tpl;
$tpl->set_block('MAIN', 'basket_row', 'BASKET_ROW');
foreach($products_in_basket as $product_id) {
//
// Get item data to display
//
$sql = "SELECT product_id, product_name, product_price
FROM products
WHERE product_id = $product_id";
$list = DB($sql);
while($row = mysql_fetch_array($list, MYSQL_ASSOC)) {
$tpl->set_var(array( 'PRODUCT_ID' => $row['product_id'],
'PRODUCT_NAME' => $row['product_name'],
'PRODUCT_PRICE' => $row['product_price']));
$tpl->parse('BASKET_ROW', 'basket_row', TRUE);
}
}
}
switch($_GET['mode']){
case 'add':
$products_in_basket[] = $_POST['product_id'];
show_page();
break;
default:
show_page();
break;
}
//
// Reset session var with new list of product_id's
//
$_SESSION['products_in_basket'] = implode(',', $products_in_basket);
##### End Code #####
ofor
>
> "Hades" <newg...@hades.me.uk> skrev i meddelandet
> news:JnCU9.33$G6X4....@news2.randori.com...
>> I've been creating a new website for a friend and am currently stuck on
> the
>> shopping cart part of the site.
>> [...]
>>
>>
> Hi
> You might want to look at
>
> http://www.pgmarket.com
>
Yes indeed... "a shopping cart" is something that has been done to death,
so why do it again? Grab something that you can use, then adapt it to your
purposes.
----------------------------------
Fast automatic Paradox/Delphi table repair at a click of a mouse!
http://www.sundialservices.com/products/chimneysweep
This URL takes me to a site about an indian market. I can't find
anything there even php related, let alone a shopping cart.
The main reason I asked about my problem is that I have a particular
structure for both the database and site and having searched
hotscripts.com not found anything that was even close to what I
wanted. I've already got an items database with different categories
and the admin side. The only bit I need now is the bit for the cart
it's self.
Any one know of anything that would help, or a cart class that would
do the job?
Thanks
Thanks.
I had a look at it and it seems pretty good. But I already have most of the
site (including catalogue) done. I was just looking for a class that would
deal with item_id's and quantities.
I found one on HotScripts.com called MyMarket that was based on a devshed
article about creating shopping carts. Handy really that I'd already read
that article :o)
Again, thankyou for your help.
Lee Conlin
"Hades" <newg...@hades.me.uk> wrote in message
news:JnCU9.33$G6X4....@news2.randori.com...