php - How can I multiply a specific value from one table to another value from another table? -


i multiply value of bottle_price of bottle_type order_bottle store value receipt_bottle in sql using php.

tblproductinfo

bottle_type(pk)   bottle_stock   bottle_price   water_price     slim              10             150            25   mini slim           10             40             10 

tblorderinfo

order_id(pk)    order_water    order_bottle    order_bottle_type(fk)    10001            2               2                   slim 

tblreceiptinfo

receipt_id(pk)   receipt_water   receipt_bottle   receipt_total 

<!doctype html>  <html>  <head>  <title>aqua serv water station</title>  </head>  <body>  <?php  	function receiptid(){  		$db = mysqli_connect('localhost', 'root', '', 'waterstationdb')  		or die ('could not connect database server' . mysqli_connect_error());  		  		$companyname = "aq-";  		$receipttype = "receipt-";  		$tempidnumber = 10001;  		  		$query = "select count(*) tblreceiptinfo";  		$result = mysqli_query($db, $query)  		or die('error querying database.');  		$row = mysqli_fetch_array($result);  		  		$increment = $row['count(*)'];  		$incrementid = $increment + $tempidnumber;  		  		$receiptidnumber = $companyname . $receipttype . $incrementid;  	  		mysqli_close($db);  		return $receiptidnumber;  	}  	  	$strreceiptid = receiptid();  	  	function bottleprice(){  		$db = mysqli_connect('localhost', 'root', '', 'waterstationdb')  		or die ('could not connect database server' . mysqli_connect_error());  		  		$query = "select intprodwater tblproductinfo";  		$result = mysqli_query($db, $query)  		or die('error querying database.');  		$row = mysqli_fetch_array($result);  		  		$query1 = "select intorderwater tblorderinfo";  		$result1 = mysqli_query($db, $query1)  		or die('error querying database.');  		$row1 = mysqli_fetch_array($result1);  		  		$query2 = mysqli_query($db, "update tblreceiptinfo set intreceiptwater = intprodwater * intorderwater");  		  	}  	  	$intreceiptwater = bottleprice();  ?>  <table align="center" bgcolor="#sky blue" border="0" cellpadding="0" cellspacing="1" width="300">  <tr>      <td align="center"><strong></br></br>receipt invoice</br></br></br></strong></td>  </tr>      <tr>      <td>      <form method="post" name="">  	<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="1" width="300">      <tr>          <td width="300">receipt id</td>          <td width="6">:</td>  		<td><input type="text" size="20" readonly name="strreceiptid" value="<?php echo $strreceiptid?>"></td>      </tr>      <tr>          <td>water price</td>          <td>:</td>          <td><input type="text" size="20" readonly name="intreceiptwater" value="<?php echo $intreceiptwater?>"></td>      </tr>  	<tr>          <td>bottle price</td>  		<td>:</td>  		<td><input type="text" size="20" readonly></td>      </tr>  	<tr>          <td>total price</td>          <td>:</td>          <td><input type="text" size="20" readonly name="intreceipttotal"></td>      </tr>  	<tr>  		<td>&nbsp;</td>	  		<td>&nbsp;</td>	  		<td><input name="btndone" type="submit" value="done"></td>  	</tr>  </table>  </form>  </td>  </tr>  </table>  <?php   	if (isset($_post['btndone']))          {       		echo "<script language='javascript' type='text/javascript'> location.href='refillermenu.php' </script>";    		}  ?>  </body>  </html>

function bottleprice() code wanted multiply values im pretty sure wrong lol

there few ways accomplish trying do.

you can directly use sql product of bottle_price * order_bottle using like:

select   (t1.bottle_price * t2.order_bottle) bottle_price tblproductinfo t1 join tblorderinfo t2   on t1.bottle_type = t2.order_bottle_type ; 

you can use value query update tblreceiptinfo table if have record receipt want update. if creating new record tblreceiptinfo have use insert sql statement.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -