PascalNouma Posted May 23, 2010 Share Posted May 23, 2010 Hello everyone, I've 2 tables in mysql file and 2 php files. The first php page will display checkboxes and once I choose checkboxes and then press submit button, it will produce 2nd php page that displays the values of checkboxes. Let's say i've a table called CAKE that has attributes called CAKETYPE & CAKEVALUE. I'll have a php page that shows checkboxes for caketypes and once I choose CAKETYPE(s) on this PHP pages, 2nd php page should display the value of the CAKETYPE(s) (CAKEVALUE) that I chose. Hope you understood what I meant. If you can give me a weblink that explains similar case, it will be great. Thanks a lot from now on. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
cmattoon Posted May 23, 2010 Share Posted May 23, 2010 If I understand you correctly, you have the following SQL table ----------dbname.cake--------- ---caketype------cakevalue--- ---chocolate-------9.99---- ---marble-------- 10.99---- ----wedding----50.99--- So the first page would have: <form name="pickacake" action="getprice.php" method="post"> <input type="checkbox" name="chocolate" value="1"> Chocolate<br> <input type="checkbox" name="marble" value="1"> Marble<br> etc... </form> The second page will see which checkboxes are checked, then return the prices for the cake? <?php require_once("accessdb.php"); $chocolate = $_POST['chocolate']; $marble = $_POST['marble']; $wedding = $_POST['wedding']; echo "<table border=\"1\"><tr><td>Cake Type</td><td>Cake Value</td></tr>"; if($chocolate == 1){ $sql = mysql_query("SELECT * FROM cake WHERE caketype='chocolate'"); while($row = mysql_fetch_assoc($sql)){ $price = $row[cakevalue]; $type = $row[caketype]; echo "<tr><td>$type</td><td>$price</td></tr>"; } }else{} if($marble == 1){ $sql = mysql_query("SELECT * FROM cake WHERE caketype='marble'"); etc... There is probably a more simple way to handle the PHP, but that's a method I use that I know works. If you only want to view the price/value of one type of cake, consider using the following HTML, which creates a dropdown box with caketypes. (The same PHP would process a radio button with name="caketype"): <form name="pickacake" action="getprice.php" method="post"> <select name="caketype"> <option value="chocolate">Chocolate</option> <option value="marble">Marble</option> <option value="wedding">Wedding</option> </select> Then, your PHP would be: <?php require_once("accessdb.php"); $caketype = $_POST['caketype']; $sql = mysql_query("SELECT * FROM cakes WHERE caketype='$caketype'"); while($row = mysql_fetch_assoc($sql)){ echo "Cake: ".$row[caketype]."<br>"; echo "Price: ".$row[cakevalue]."<p>"; } If the Milk Tea Shop page is yours, consider formatting your currency to include decimal places. While most people will understand that ($5.5) is $5.50, it looks more professional if you have the trailing zeros ($1.00 instead of $1). Quote Link to comment Share on other sites More sharing options...
ignace Posted May 23, 2010 Share Posted May 23, 2010 I'm probably one of the few who thought of the Decorator pattern when they looked at your attached image. Quote Link to comment Share on other sites More sharing options...
PascalNouma Posted May 23, 2010 Author Share Posted May 23, 2010 Unfortunately I got this error message: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\action.php on line 23 $sql = mysql_query("SELECT * FROM cake WHERE caketype='chocolate'"); while($row = mysql_fetch_assoc($sql)){ $price = $row[cakevalue]; $type = $row[caketype]; echo "<tr><td>$type</td><td>$price</td></tr>"; } How could I fix this? Thanks for your interest and your help. 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.