ryld Posted April 5, 2007 Share Posted April 5, 2007 Hey guys! I tried searching for the answer, but there were so many posts, and the ones I looked at (a lot) didn't quite seem to answer the question. I'm writing a PHP script, and I know exactly how I want it to work, and what I want it to do when certain things happen. I also know how to make everything work. Well, everything except for this! The goal of the application is to perform sales. It will use a point and click interface. It should look something like this item 1item 2item 3item 4 in it's most basic form, except that it will use images instead of text. Now, when you click the image, it will store a variable. For example, if you were to click ITEM 1, then it would store the variable '8.95'. If you click ITEM 2, it would store '3.99'. Any ideas? Quote Link to comment Share on other sites More sharing options...
btherl Posted April 5, 2007 Share Posted April 5, 2007 That sounds more suited to javascript (php would still be involved on submission of the data). Quote Link to comment Share on other sites More sharing options...
trq Posted April 5, 2007 Share Posted April 5, 2007 Store them where? You need to be allot more specific. It seems to me that Javascript would be better suited anyhow, php runs on the server while Javascript on the client (forms). Quote Link to comment Share on other sites More sharing options...
ryld Posted April 5, 2007 Author Share Posted April 5, 2007 Some would need to be stored in a variable, others in an array. Then later some of the variables/arrays would need to be stored into a database. Quote Link to comment Share on other sites More sharing options...
trq Posted April 5, 2007 Share Posted April 5, 2007 Your buttons will need submit the data back to the server via forms. Once on the server, you will find the values in the $_GET[] array by default, or if you make your form methods post, the $_POST[] array. Quote Link to comment Share on other sites More sharing options...
Fergusfer Posted April 5, 2007 Share Posted April 5, 2007 Some would need to be stored in a variable, others in an array. Then later some of the variables/arrays would need to be stored into a database. Create a link that passes an identifier to a script. For example: <a href="script.php?id=1"> <img src="some_image.jpg" alt="click to order"> </a> Then the server processes it as so: <?php // script.php session_start(); $prices = array(1 => 8.95, 2 => 3.99); if (isset($_GET['id']) && is_numeric($_GET['id'])) { if (!isset($_SESSION['total'])) $_SESSION['total'] = 0; $_SESSION['items'][] = $_GET['id']; $_SESSION['total'] += $prices[$_GET['id']]; } else { echo "<p>invalid product ID</p>"; } ?> None of this code will store the data in a database. It'll just track it while the user's session persists. The next step -- storing the data in a database -- seems to be beyond the scope of your current topic. Quote Link to comment 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.