Home  • Programming • PHP
explain the function if any one can function addtocart($pid,$q){ if(is_array($_SESSION['cart'])){ if(product_exists($pid)) return; $max=count($_SESSION['cart']); $_SESSION['cart'][$max]['productid']=$pid; $_SESSION['cart'][$max]['qty']=$q; } else{ $_SESSION['cart']=array(); $_SESSION['cart'][0]['productid']=$pid; $_SESSION['cart'][0]['qty']=$q; } }

Comments 26


Where do you find this code?
Study about array to get this function.
Sir, I was just study a shopping cart but this function make me
bordom, several question arise repeatedly .......
See the table
ProductIDQty
101
115
122
If you want to add table data to session variable then this function will help you. Just call it with record data like addtocart(10,2) addtocart(11,5) addtocart(12,2)
here associate key cart is table name, $max is auto id, and (productid,qty) are fields if you compare to table with session variable
This is three dimensional session variable
Thank you sir...Think now I'll
Let me explain the above code..
You might be got it to the codeigniter shopping cart class at user_guide/libraries/cart.html in your installation area
No...not from codeigniter ..
ok just think that as a user u have visited a ecomerce site and then u have listed some product
and the second step can be expressed..
ur data is important to remember, because else some way u cant purchase these product,
so u have to store it to a session variable and if you choose one product again and again u need to remember the quantity in order to bill and also you don't need the same product to be overwritten but need the quantity to increment
but there sould be a limitation on a product purchase to chk some where on your resource file that chk the $max session variable
Yes...exactly ...
if you have visited the first time the there is no purchase order on your cart in that case the Else statment has the probability to create a new cart list
hope it will make sense
So we may conclute the function is a helper fucntion for creating the cart list or adding product on a cart list
Thnks ....it makes more clear..
Dr sir..Does there any restriction or rule where it has said that Every user must have to upload a profile picture? event i don't think that stackoverflow has that rule so far.. please forgive
To prevent fake account in VCampus we are not allowing members to upload photo by them without photo verification not just like facebook or stackoverflow community.
how may u varify my photo when you don't know me and there is no posibility to meet at all
It is not possible to prevent 100% that we know but Psychologically people provide his or her real photo initially. After long period possibility goes down
Besides this is a learning community not just like facebook so that trends to be lower to hide himself or herself from others. Moreover, If student wants to earned certificate from VCampus then they may not provide fake info. Some other features in VC also help us to prevent to fake account like reputation system, quizzes with grading system and more.
About Author
Most Monira Begum
Copyright © 2025. Powered by Intellect Software Ltd