LearningKid Posted January 11, 2010 Share Posted January 11, 2010 Hi im tryin to get some calculations done but im not sure wat im doing wrong can anyone hlp <?php session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } echo "Hi $_SESSION[myusername] <br /><br />"; ?> <html> <body> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="modify"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "SELECT * FROM `modify` ORDER BY `ID` ASC"; $result = mysql_query($sql); $rows = mysql_num_rows($result); ?> <form action="count.php" method="post"> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab1').style.display='block';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Pages</a></strong><br /> <div id="tab1" style="display:none; font-size:11;"> Single Sided B&W <input type="radio" name="bw/c" value="1" /><br /> Double Sided B&W <input type="radio" name="bw/c" value="2" /><br /> Single Sided Colour <input type="radio" name="bw/c" value="3" /><br /> Double Sided Colour <input type="radio" name="bw/c" value="4" /><br /> <?php echo '<select name="Ptype">'; while($data = mysql_fetch_assoc($result)) { echo '<option name=bw/c/pt value="'.$data['Valeu'].'">'.$data['Name'].'</option>'."\n"; } echo '</select>'; ?> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab2').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Binding and Stapling</a></strong><br /> <div id="tab2" style="display:none;"> None <input type="radio" name="s/b" value="0" /><br /> Spiral <input type="radio" name="s/b" value="1" /><br /> <select name="Spitype"> <option name="s/b/spty" value="1a" >Cerlox/Comb <option name="s/b/spty" value="1b" >Wireless <option name="s/b/spty" value="2c" >Coil </select> <br> Staples <input type="radio" name="s/b" value="2" /><br /> <select name="Spitype"> <option name="s/b/stty" value="2a" >Top <option name="s/b/stty" value="2b" >Side <option name="s/b/stty" value="2c" >Bottom </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab3').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Covers</a></strong><br /> <div id="tab3" style="display:none;"> None<input type="radio" name="c" value="0" /><br> Front Cover<br> Standard Front Cover <input type="radio" name="c" value="1" /><br> <select name="CovType"> <option name="c/cty" value="1a" >No Printing <option name="c/cty" value="1b" >Print B&W <option name="c/cty" value="1c" >Print Colour </select><br> <select name="Ptype"> <option name="bw/c/pt" value="1" selected>[Paper Colour/Type] <option name="bw/c/pt" value="1" >White <option name="bw/c/pt" value="2" >Red <option name="bw/c/pt" value="3" >Blue <option name="bw/c/pt" value="4" >Green </select><br> Standard Back Cover <input type="radio" name="c" value="2" /><br> <select name="CovType"> <option name="c/cty" value="2a" >No Printing <option name="c/cty" value="2b" >Print B&W <option name="c/cty" value="2c" >Print Colour </select><br> <select name="Ptype"> <option name="bw/c/pt" value="1" selected>[Paper Colour/Type] <option name="bw/c/pt" value="1" >White <option name="bw/c/pt" value="2" >Red <option name="bw/c/pt" value="3" >Blue <option name="bw/c/pt" value="4" >Green </select><br> Premium Back Cover <input type="radio" name="c" value="3" /><br> <select name="CovType"> <option name="c/cty" value="3a" >Clear <option name="c/cty" value="3b" >Vinyl Black <option name="c/cty" value="3c" >Linen Blue </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab4').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Tabs</a></strong><br /> <div id="tab4" style="display:none;"> Bank<br> <select name="BaType"> <option name="t/tty" value="1a" >Full-cut 5 </select><br> Font<br> <select name="FoType"> <option name="t/tty" value="2a" >Arial </select><br> Label<br> <input type="text"><br> Font Size<br> <select name="F/size"> <option name="t/tty" value="3a" >12 <option name="t/tty" value="3b" >10 <option name="t/tty" value="3c" >8 </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab5').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Special Instuctions</a></strong><br /> <div id="tab5" style="display:none;"> <textarea></textarea><br> <input type="checkbox" name="si/cty" value="1">Cutting<br> <select name="si/cty"> <option name="si/cty" value="1a" >Horizontal <option name="si/cty" value="1b" >Vertical <option name="si/cty" value="1c" >BlahBlah </select><br> <input type="checkbox" name="si/fty" value="1">Folding<br> <select name="si/fty" > <option name="si/fty" value="2a" >Horizontal <option name="si/fty" value="2b" >Vertical <option name="si/fty" value="2c" >BlahBlah </select><br> <input type="checkbox" name="si/lty" value="1">Laminating<br> <select name="si/lty" > <option name="si/lty" value="3a" >5mm <option name="si/lty" value="3b" >10mm </select><br> </div> <input type="submit" value="Total" /> </form> <?php require_once ('includes.php'); // set quantity $quantity = 4; $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="modify"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "SELECT * FROM `modify` ORDER BY `ID` ASC"; $result = mysql_query($sql); $rows = mysql_num_rows($result); while($data = mysql_fetch_assoc($result)) { $answer = $_POST['bw/c/pt']; if ($answer == $data['Valeu']) { $origPrice = $data['Valeu'] ; } else { // set original and current unit price $origPrice = 20; } } // set original and current unit price $currPrice = $origPrice * $quantity; // calculate difference in price $tax = 16; // calculate percentage change in price $PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0); ?> <strong> <div id="tab6" style="display:block;"> <table border="1" cellpadding="5" cellspacing="0" > <tr><td>Quantity</td><td>Cost price Per Page</td><td>Current price Without Vat</td><td>Vat</td><td>Total Cost With Vat</td> </tr> <tr align="center"><td> <?php echo $quantity; ?></td><td>$ <?php echo $origPrice; ?></td><td>$ <?php echo $currPrice; ?></td><td> <?php echo $tax; ?>%</td><td>$ <?php echo $PriceTaxed; ?></td> </tr> </table><br /><br /> </div> <a href="logout.php">leave</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188066-calculations-not-working/ Share on other sites More sharing options...
ignace Posted January 11, 2010 Share Posted January 11, 2010 $PriceTaxed = $currPrice * (1 + $tax / 100); Link to comment https://forums.phpfreaks.com/topic/188066-calculations-not-working/#findComment-992843 Share on other sites More sharing options...
LearningKid Posted January 11, 2010 Author Share Posted January 11, 2010 Ok so i kinda played around and got it working now i jsut need it to select the correct Valeu cause it just keeps selecting the last valeu from my db, i want it select watever value i select from the dropdown menu. Any ideas how to do tht anyone? <?php session_start(); if(!session_is_registered(myusername)){ header("location:login.php"); } echo "Hi $_SESSION[myusername] <br /><br />"; ?> <html> <body> <?php $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="modify"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "SELECT * FROM `modify` ORDER BY `ID` ASC"; $result = mysql_query($sql); $rows = mysql_num_rows($result); ?> <form action="count.php" method="post"> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab1').style.display='block';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Pages</a></strong><br /> <div id="tab1" style="display:none; font-size:11;"> Single Sided B&W <input type="radio" name="bw/c" value="1" /><br /> Double Sided B&W <input type="radio" name="bw/c" value="2" /><br /> Single Sided Colour <input type="radio" name="bw/c" value="3" /><br /> Double Sided Colour <input type="radio" name="bw/c" value="4" /><br /> <?php echo '<select name="Ptype">'; while($data = mysql_fetch_assoc($result)) { echo '<option name="bw/c/pt" value="'.$data['Valeu'].'">'.$data['Name'].'</option>'."\n"; } echo '</select>'; ?> </div><!-- <strong><a href="javascript:void(0);" onClick="document.getElementById('tab2').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Binding and Stapling</a></strong><br /> <div id="tab2" style="display:none;"> None <input type="radio" name="s/b" value="0" /><br /> Spiral <input type="radio" name="s/b" value="1" /><br /> <select name="Spitype"> <option name="s/b/spty" value="1a" >Cerlox/Comb <option name="s/b/spty" value="1b" >Wireless <option name="s/b/spty" value="2c" >Coil </select> <br> Staples <input type="radio" name="s/b" value="2" /><br /> <select name="Spitype"> <option name="s/b/stty" value="2a" >Top <option name="s/b/stty" value="2b" >Side <option name="s/b/stty" value="2c" >Bottom </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab3').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Covers</a></strong><br /> <div id="tab3" style="display:none;"> None<input type="radio" name="c" value="0" /><br> Front Cover<br> Standard Front Cover <input type="radio" name="c" value="1" /><br> <select name="CovType"> <option name="c/cty" value="1a" >No Printing <option name="c/cty" value="1b" >Print B&W <option name="c/cty" value="1c" >Print Colour </select><br> <select name="Ptype"> <option name="bw/c/pt" value="1" selected>[Paper Colour/Type] <option name="bw/c/pt" value="1" >White <option name="bw/c/pt" value="2" >Red <option name="bw/c/pt" value="3" >Blue <option name="bw/c/pt" value="4" >Green </select><br> Standard Back Cover <input type="radio" name="c" value="2" /><br> <select name="CovType"> <option name="c/cty" value="2a" >No Printing <option name="c/cty" value="2b" >Print B&W <option name="c/cty" value="2c" >Print Colour </select><br> <select name="Ptype"> <option name="bw/c/pt" value="1" selected>[Paper Colour/Type] <option name="bw/c/pt" value="1" >White <option name="bw/c/pt" value="2" >Red <option name="bw/c/pt" value="3" >Blue <option name="bw/c/pt" value="4" >Green </select><br> Premium Back Cover <input type="radio" name="c" value="3" /><br> <select name="CovType"> <option name="c/cty" value="3a" >Clear <option name="c/cty" value="3b" >Vinyl Black <option name="c/cty" value="3c" >Linen Blue </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab4').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Tabs</a></strong><br /> <div id="tab4" style="display:none;"> Bank<br> <select name="BaType"> <option name="t/tty" value="1a" >Full-cut 5 </select><br> Font<br> <select name="FoType"> <option name="t/tty" value="2a" >Arial </select><br> Label<br> <input type="text"><br> Font Size<br> <select name="F/size"> <option name="t/tty" value="3a" >12 <option name="t/tty" value="3b" >10 <option name="t/tty" value="3c" >8 </select><br> </div> <strong><a href="javascript:void(0);" onClick="document.getElementById('tab5').style.display='block';document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab6').style.display='none';" onDblClick="document.getElementById('tab1').style.display='none';document.getElementById('tab2').style.display='none';document.getElementById('tab3').style.display='none';document.getElementById('tab4').style.display='none';document.getElementById('tab5').style.display='none';document.getElementById('tab6').style.display='none';">Special Instuctions</a></strong><br /> <div id="tab5" style="display:none;"> <textarea></textarea><br> <input type="checkbox" name="si/cty" value="1">Cutting<br> <select name="si/cty"> <option name="si/cty" value="1a" >Horizontal <option name="si/cty" value="1b" >Vertical <option name="si/cty" value="1c" >BlahBlah </select><br> <input type="checkbox" name="si/fty" value="1">Folding<br> <select name="si/fty" > <option name="si/fty" value="2a" >Horizontal <option name="si/fty" value="2b" >Vertical <option name="si/fty" value="2c" >BlahBlah </select><br> <input type="checkbox" name="si/lty" value="1">Laminating<br> <select name="si/lty" > <option name="si/lty" value="3a" >5mm <option name="si/lty" value="3b" >10mm </select><br> </div> --> <input type="submit" value="Total" /> </form> <?php require_once ('includes.php'); // set quantity $quantity = 4; $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="modify"; // Table name // Connect to server and select databse. $answer = $_POST['bw/c/pt']; if ($answer == $data['Valeu']) { mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql= "SELECT * FROM `modify` WHERE Price = Valeu"; $result = mysql_query($sql); $rows = mysql_num_rows($result); while($data = mysql_fetch_assoc($result)) { $origPrice = $data['Price'] ; } } else { // set original and current unit price $origPrice = 20; } // set original and current unit price $currPrice = $origPrice * $quantity; // calculate difference in price $tax = 16; // calculate percentage change in price $PriceTaxed = round((($currPrice * $tax)/100) + $currPrice,0); ?> <strong> <div id="tab6" style="display:block;"> <table border="1" cellpadding="5" cellspacing="0" > <tr><td>Quantity</td><td>Cost price Per Page</td><td>Current price Without Vat</td><td>Vat</td><td>Total Cost With Vat</td> </tr> <tr align="center"><td> <?php echo $quantity; ?></td><td>$ <?php echo $origPrice; ?></td><td>$ <?php echo $currPrice; ?></td><td> <?php echo $tax; ?>%</td><td>$ <?php echo $PriceTaxed; ?></td> </tr> </table><br /><br /> </div> <a href="logout.php">leave</a> </body> </html> Link to comment https://forums.phpfreaks.com/topic/188066-calculations-not-working/#findComment-992890 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.