2 Replies - 266 Views - Last Post: 09 March 2014 - 11:16 AM Rate Topic: -----

#1 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

drop down list selection

Posted 09 March 2014 - 06:28 AM

<?php

include('connection.php');

$sql = "select * from billing_table";

$result = mysql_query($sql,$con) or die(mysql_error());


?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="JS/calculate.js" type="text/javascript">
</script>
</head>

<body>
<form action="" method="post">
<table border="0" align="center" bgcolor="#CCCCCC">
<tr>
<td> Branch Name </td>

<td> 
<?php $sql = "SELECT Bname FROM billing_table  GROUP BY Bname";

$result = mysql_query($sql,$con);
if ($result != 0) {
    
    echo '<select name="branch">';
    echo '<option value="">Select</option>';
   
    $num_results = mysql_num_rows($result);
    for ($i=0;$i<$num_results;$i++) {
        $row = mysql_fetch_array($result);
        $name = $row['Bname'];
        echo '<option value="' .$name. '">' .$name. '</option>';
    }
   
    echo '</select>';
    
}
?>
</td>
</tr>

<tr>
<td>Product Name </td>
<td>
 <?php $sql = "SELECT pname FROM billing_table  GROUP BY pname";

$result = mysql_query($sql,$con);
if ($result != 0) {
    
    echo '<select name="product">';
    echo '<option value="">Select</option>';
   
    $num_results = mysql_num_rows($result);
    for ($i=0;$i<$num_results;$i++) {
        $row = mysql_fetch_array($result);
        $name = $row['pname'];
        echo '<option value="' .$name. '">' .$name. '</option>';
    }
   
    echo '</select>';
    
}
?>
</td>
</tr>

<tr>
<td> Price </td>
<td> <input type="text" name="price" id="price" />
</td>
</tr>

<tr>
<td> Quantity </td>
<td> 
<input type="text" name="quantity" id="quantity"  />
</td>
</tr>

<tr>
<td> Total Amount </td>
<td> <input type="text" name="total" id="total" />
</td>
</tr>

<tr> 
<td> Paid Amount </td>
<td> <input type="text" name="paid" id="paid" />
</td> 
</tr>

<tr> 
<td> Balance Amount </td>
<td> <input type="text" name="bal" id="bal" />
</td> 
</tr>

<tr>
<td colspan="2" align="center"> <input type="button" value="calculate"  onclick="calculate()" /></td>
</tr>

</table>
</form>
</body>
</html>




So this code is fetching me the values from the database and displaying inside the drop down but what i need is on selecting the product from the list i want the price to be displayed from the database for tat product inside the textbox.. So can anyone guide me regarding this

Is This A Good Question/Topic? 0
  • +

Replies To: drop down list selection

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,590
  • Joined: 08-August 08

Re: drop down list selection

Posted 09 March 2014 - 08:30 AM

You'll probably want to use Ajax. It's Javascript sending a request to the server to run a script and send back new information. Look it up.
You definitely need to learn and use PREPARED STATEMENTS. MySQL functions are deprecated for good reason. There's a great tutorial on PDO in the PHP tutorials section.
Was This Post Helpful? 0
  • +
  • -

#3 sangeetha_s  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 94
  • Joined: 15-November 12

Re: drop down list selection

Posted 09 March 2014 - 11:16 AM

Thank you i will try with Ajax
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1