Jump to content

Calculations


LearningKid

Recommended Posts

hi why cant i use $data['Valeu'] as the amount i want its a value im pullin from a db.

<?php
$quantity = 4;
$answer = $_POST['bw/c/pt'];
    if ($answer == $data['Valeu']) {
        
        $origPrice =  22 ;
        
    }
    
    else {
       
       
// set original and current unit price
$origPrice = 20;
}
?>

 

Link to comment
https://forums.phpfreaks.com/topic/186591-calculations/
Share on other sites

why cant i use $data['Valeu'] as the amount

 

You can, but that would require that the code on your page is correctly setting $data['Valeu'] to what you expect. Have you echoed $data['Valeu'] so that you know what it contains? Should 'Valeu' be 'Value'?

Link to comment
https://forums.phpfreaks.com/topic/186591-calculations/#findComment-985462
Share on other sites

ok so this is what i have.

in my db i have a table named Valeu which has amounts tht i want to be added lik 2,4,6,8, etc. however i dont get it to add the valeu amt in calculations.

<?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>';
?> 
<?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;
}
}
$quantity = 4;
       
// 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>


  </body>
</html> 

Link to comment
https://forums.phpfreaks.com/topic/186591-calculations/#findComment-985464
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.