Ive been working with php for about 3 weeks now and im loving it. I'm creating a database driven shopping cart on my RAQ4 using mysql and php. I've gotten the cart to do do every function in managing a online store but one thing.
I'm using arrays to store all of the items in their cart. Each variable in the array contains the item number and quantity desired. I need the client to be able to remove a varable or adjust the quantity value of a variable within the array. How can i do this?
Can anybody shed some light on this or am I barking up the wrong tree?
Or even better does anybody know of a better way of storing the cart info?
Thank you
Can you remove a variable from an array???
Moderator: General Moderators
Its my understanding that this could start to strain the system if the site or multiple sites running this were to become very busy making transactions to the database creating new rows as everybody were shopping. If you dont really think this would be a problem and I'm being over cautious let me know and I'll go that route because it was a early consideration.
Also if i did go this way should the persons cart be marked with a sesion ID of some type to keep track of them before they enter a name at checkout time and get a cusyomer ID? And what would be the most effective way to do this?
Thanks
Also if i did go this way should the persons cart be marked with a sesion ID of some type to keep track of them before they enter a name at checkout time and get a cusyomer ID? And what would be the most effective way to do this?
Thanks
- hob_goblin
- Forum Regular
- Posts: 978
- Joined: Sun Apr 28, 2002 9:53 pm
- Contact:
http://www.php.net/unset
example:
you might want to look into objects though; http://www.php.net/oop
example:
Code: Select all
$arrayї'0'] = "foo";
$arrayї'1'] = "bar";
echo $arrayї'1']; // PRINTS "bar"
unset($arrayї'1']);
echo $arrayї'1']; // PRINTS ""just be aware that unset will leave a hole in your array.
That's not too bad but you should keep it in mind. e.g.the second loop will only output one element, since after unset
That's not too bad but you should keep it in mind. e.g.
Code: Select all
<?php
$a = array('a', 'b', 'c');
for($i=0; $i!=count($a); $i++)
echo $a[$i], ' ';
echo "<br/>\n";
unset($a[1]);
for($i=0; $i!=count($a); $i++)
echo $a[$i], ' ';
?>- $a is equal to array(0=>'a', 2=>'c')
- count($a) will return 2
- and the loop therefor tries to access $a[0] and $a[1], the latter is no more.