LearningKid Posted December 31, 2009 Share Posted December 31, 2009 Hi this is some calculation i want but i seem to be doing a few things wrong can anyone hlp me? i want when i get $answer == data[Valeu] then the price must become data[Valeu] any hlp plz plz plz. <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>'; ?> <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 = 22 ; } 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/186796-cant-seem-to-get-coding-right/ Share on other sites More sharing options...
Deoctor Posted December 31, 2009 Share Posted December 31, 2009 try mysql_fetch_array instead of assoc Link to comment https://forums.phpfreaks.com/topic/186796-cant-seem-to-get-coding-right/#findComment-986419 Share on other sites More sharing options...
LearningKid Posted December 31, 2009 Author Share Posted December 31, 2009 i did but still seem to skip the part where its supposed to change the value when i select something else Link to comment https://forums.phpfreaks.com/topic/186796-cant-seem-to-get-coding-right/#findComment-986422 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.