Jump to content

Recommended Posts

Hi all,

 

Need a bit of help here.

 

In my database I have two products. Each product is made up of components. This is the product table:

 

ProductID  Description

---------  -----------

    1          Timer

    2          Strobelight

 

This is the components table:

 

ComponentID    Parttype

------------    -----------

    1              20K resistor

    2              Strobelight

 

This is the compperprod table:

 

CPPID  ProductID  ComponentID  Quantity

------  ----------  ------------  --------

    1          1                1              2

    2          2                1              5

    3          2                2              1

 

As you can see from the above table product 1 and product 2 shares the same component namely the 20K resistor.

 

What I am trying to achieve here is when I request a quantity of 5 for product 1 and a quantity of 3 for product 2, it must multiply all the components of product 1 with 5 and all the components of product 2 with 3. Where products shares the same components it must take the multiplied values and add them together.

 

This is my code that send the product quantities to another page.

 

<html>
<head><link type="text/css" href="stock.css" rel="stylesheet"></head>
<body bgcolor="#ffffff" topmargin="0" leftmargin="0">
<table>
<?php
include ("dbconnect.php");
require ("emreg.php");
?>	
</table>
<form name="stocktake" method="post" action="productcalculation.php">
<table align="center" width="100%" cellpadding="1" cellspacing="0" border="0" bgcolor="white">
<tr><td colspan="2"><hr size="1" color="#778899"></td></tr>
<tr>
<td align="center" valign="top">
	<table width="50%" cellpadding="0" cellspacing="0" border="1" bordercolor="#004080">
		<tr align="center" bgcolor="#004080">
			<td width="30%"><font class="tblhdr">Parttype</font></td>
			<td><img src="images/spacer.gif" width="12" height="20" border="0"></td>
			<td width="30%"><font class="tblhdr">Description</font></td>						
		</tr>
		<tr>
			<td colspan="15">					
				<table id="componentList"  cellpadding="0" cellspacing="1" border="0" width="100%" style="CURSOR: hand">
				<?php
				$productQuery = mysql_query("SELECT ProdID,Description FROM products");

				while ($row = mysql_fetch_assoc($productQuery)) {		
						echo "<tr align=center>"; 
						echo "<td width=30% class=tableData>".$row['Description']."</td>";
						echo "<td width=10% class=tableData><input type=text name=ProdID".$row['ProdID']." value=0 size=5></td>";
						echo "</tr>";							
					}
				?>
				</table>					
			</td>						
		</tr>
	</table>
</td>	
</tr>
<tr>
<td valign="top" align="center"><input type="hidden" name="action"><input type="submit" name="btnUpdate" value="Request"><?php echo $msg; ?><br></td>		
</tr>
</table>
</form>
</body>
</html>

 

How do I code this?

Link to comment
https://forums.phpfreaks.com/topic/56683-addition-of-values-in-database/
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.