raptor30506090 Posted July 2, 2012 Share Posted July 2, 2012 Hi guys question is there a generater in php what will generate id for my session and back to the id again for my query thanks Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/ Share on other sites More sharing options...
PeoMachine Posted July 2, 2012 Share Posted July 2, 2012 What you're trying to do? You can use the uniqid function. Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358557 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 Thanks for quick reply ok then how do i say get id=1 from uniqid thanks Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358559 Share on other sites More sharing options...
ManiacDan Posted July 2, 2012 Share Posted July 2, 2012 Explain what you're trying to do. Do you want a unique ID, or do you want the number 1? What will this be used for and why do you want it? Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358560 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 ok what im trying to do is get the session to add new product in with same id so product_1 id_1 and product_2 id_1 the reason for this is so i can add options to the cart only way at mo i can think of doing it cheers Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358561 Share on other sites More sharing options...
ManiacDan Posted July 2, 2012 Share Posted July 2, 2012 You don't have a database with product IDs? The session is unique for every user, they don't SHARE the session like they do a database. Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358569 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 No what im trying to do is my products will have options like size 8 ?4.99 size 9 ?5.99 so when at the mo they select an option it replaces the last price so im trying to make it add a new session name hope that helps or im going mad Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358573 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 ok im not getting any were with this can some one give me an idea how to go about putting options in a form to make choice payment in my cart and if they add more than 1 of the same Thanks sorry to be a pain Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358581 Share on other sites More sharing options...
ManiacDan Posted July 2, 2012 Share Posted July 2, 2012 If English is not your first language, just try to say MORE on the subject so we can get an idea of what you mean. What you need to be doing is storing the cart in the session using the product ID as the key: $_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) ); Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358583 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 this is were im a bit stuck if they orderd $_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) ); and then same person orderd $_SESSION['cart'][$productId] = array('quantity' => 5, 'price' => 19.99, 'options' => array( 'color' => 'blue', 'size' => 'large' ) ); would that over right the first order? thanks Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358591 Share on other sites More sharing options...
ManiacDan Posted July 2, 2012 Share Posted July 2, 2012 When you go to add a product to the cart, check to see if it's already in the cart. if it is, only update the quantity. Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358592 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 Sorry ManiacDan if you looked at what i put iv changed the last 3 colour , price and size would this create a new product listing so we would have two products in the cart? Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358603 Share on other sites More sharing options...
ManiacDan Posted July 2, 2012 Share Posted July 2, 2012 I don't know, that's a business rule. What do you want to happen when they do that? If I bought 3 green shirts at $9.99, then 15 red shirts at $8.00, would you really make an entry for 18 shirts? How would you ever figure out the original order? If it were me, I'd probably use the same idea I gave you earlier, except $_SESSION['cart'][$productId] would be an array of products, each with their own quantities and specifications. if all specifications matched, I'd update the quantity. If any one of them did not match, I'd add a new row. Obviously, if $_SESSION['cart'][$productId] didn't already exist I'd add a new array of products, like this: $_SESSION['cart'][$productId] = array( array( 'quantity' => 5, 'price' => 9.99, 'options' => array( 'color' => 'green', 'size' => 'medium' ) ) ); Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358614 Share on other sites More sharing options...
raptor30506090 Posted July 2, 2012 Author Share Posted July 2, 2012 thank you for your time ill go and have a play see what i can do Cheers Quote Link to comment https://forums.phpfreaks.com/topic/265112-id/#findComment-1358616 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.