Jump to content

Cant seem to get coding right


LearningKid

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.