Hi there,
I have 3 mysql tables… one is just a daily registry, logging in details of a particular stock from a certain supplier. The other is to store sum of the each stock’s quantity and the other to store details of an order. The one that stores details of an order should interact with the one that stores the sum of each stock’s quantity.
Below is my code snippet:
[php]
//Part 1: Retrieves from bridge table
$q1 = “SELECT quantity FROM bridge WHERE Category=’$cat’ AND type = ‘$typ’ AND family = ‘$fam’”;
$r1 = mysqli_query($dbc, $q1) or die (mysqli_error($dbc));
$q2 = "SELECT sacks FROM bridge WHERE Category = '$cat' AND type = '$typ' AND family= '$fam'";
$r2 = mysqli_query($dbc, $q2) or die (mysqli_error($dbc));
$r11 = mysqli_fetch_array($r1);
$r22 = mysql_fetch_array($r2);
$r4 = $r11 + $qty;
$r5 = $r22 + $sck;
$q3 = "UPDATE bridge SET quantity='$r4' AND sacks='$r5' WHERE type = '$typ'";
$stmt2 = mysqli_query($dbc, $q3) or die (mysqli_error($dbc));
// Part 2: Add the order to orders table:
$q = “INSERT INTO orders (entry_date, customer, category, family, type, quantity, unit_price, tot_price, rate, sacks )
VALUES (’$ed’, ‘$cust’, ‘$cat’, ‘$fam’, ‘$typ’, ‘$qty’, ‘$up’, ‘$tp’, ‘$rte’, ‘$sck’)”;
$stmt = mysqli_query($dbc, $q) or die (mysqli_error($dbc));
// Check the results…
if (($stmt) && ($stmt2)) {
// Print a message:
echo 'Thank you. Order is Submitted';
} else { // Error!
echo 'Your submission could not be processed due to a system error.';
}
mysqli_close($dbc);[/php]
Brief Explanation:
Part 1 should pull off some information (quantity and sacks) from the table that stores the sum of the stock’s quantity, assign that information to a variable and then get the new value being ordered and add to it the one pulled from the table and later post it back to that same table.
Part 2 just gets the order and posts it to the orders table.
I am stuck trying to achieve this… Any thoughts are welcome…
Regards,