28rain Posted April 13, 2009 Share Posted April 13, 2009 Basically im newish to php and im having a go at making a cart, and i have already made the infastructure of the other tables. The cart tutorials are really unclear to me so does anybody know a decent tuorial or explanation to this line of code... <a href="cart.php?action=add_item&id=<?php echo $row["itemId"]; ?>&qty=1">Add Item</a> Thanks ??? Quote Link to comment https://forums.phpfreaks.com/topic/153870-does-anyone-know-a-tutorial-where-this-is-explained/ Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 Looks like when someones clicks on that link it sends them to the processing page (cart.php) where it's going to add the item that they selected ($_GET['id']) with the quantity of 1 ($_GET['qty']). It's utilizing the GET method. The link is generated dynamically, and the value for the URL parameter 'id' is generated from the results of the query to the database. Quote Link to comment https://forums.phpfreaks.com/topic/153870-does-anyone-know-a-tutorial-where-this-is-explained/#findComment-808668 Share on other sites More sharing options...
28rain Posted April 13, 2009 Author Share Posted April 13, 2009 So where's the id going to be added to? Is it adding to the session? And what about all the ? e.g cart.php?action Quote Link to comment https://forums.phpfreaks.com/topic/153870-does-anyone-know-a-tutorial-where-this-is-explained/#findComment-808671 Share on other sites More sharing options...
dadamssg Posted April 13, 2009 Share Posted April 13, 2009 the question marks seperates the file from the variables being set via the url...cart.php is the same as cart.php? the variables are set via $_GET['variable']....so the 'action' variable is set to Add_item...the &'s seperate each variable and what they're set to...the file(cart.php) pulls those variables out of the url and uses them in the script. Quote Link to comment https://forums.phpfreaks.com/topic/153870-does-anyone-know-a-tutorial-where-this-is-explained/#findComment-808685 Share on other sites More sharing options...
Maq Posted April 13, 2009 Share Posted April 13, 2009 The skeleton of your script probably looks something like this. So first let me explain how it's being generated. $sql = "SELECT * FROM items"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?> &qty=1">Add Item } ?> Your script queries the database and grabs all of the unique ID's for the items and assigns 'id' to it. The '?' and '&' characters are how you append these values to the URL. '?' is used for the very first one, and any additional values you must use the '&' symbol. If you go to the cart.php page, and look for 'add_item', which is the action you're taking when you get there, then you will see $_GET['id'] and $_GET['qty'] which will be used to add that item to the customers cart (session or DB) with the quantity of 1. Quote Link to comment https://forums.phpfreaks.com/topic/153870-does-anyone-know-a-tutorial-where-this-is-explained/#findComment-808689 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.