/    Sign up×
Community /Pin to ProfileBookmark

I have created a form to fill out to order products (table = merchandise) and I have created a table for the merchandise (table – merchandise_inventory)

The user is allowed to have 10 items per order (purchase1 — purchase10) – each purchase coinsides with an item in the inventory. I am trying to show inventory numbers as they drop after a purchase is made.

I am able to get it to work for only 1 item in the inventory – it wont loop for all items.

[code=php]
$sql=”SELECT * FROM merchandise_inventory ORDER BY merchandise”;
$result=mysql_query($sql) or die(“Couldn’t execute query: “.mysql_error());
while($rows=mysql_fetch_array($result)){
$merchandise=$rows[‘merchandise’];
$quantity=$rows[‘quantity’];
$reorder=$rows[‘reorder’];
$update= ‘<a href=”update-inventory.php?id=’.$rows[‘id’].'”>update</a>’;
if ( $quantity <= $reorder ) {
$lastcell= “<span style=”color:#ff0000″>Reorder</span>”;
} else {
$lastcell= “&nbsp;”;
}
$purchases=”SELECT * FROM merchandise”;
$result = mysql_query($purchases);
while ($rows=mysql_fetch_array($result)) {
$purchase1=$rows[‘purchase1’];
$purchase2=$rows[‘purchase2’];
$purchase3=$rows[‘purchase3’];
$purchase4=$rows[‘purchase4’];
$purchase5=$rows[‘purchase5’];
$purchase6=$rows[‘purchase6’];
$purchase7=$rows[‘purchase7’];
$purchase8=$rows[‘purchase8’];
$purchase9=$rows[‘purchase9’];
$purchase10=$rows[‘purchase10’];
$quantity1=$rows[‘quantity1’];
$quantity2=$rows[‘quantity2’];
$quantity3=$rows[‘quantity3’];
$quantity4=$rows[‘quantity4’];
$quantity5=$rows[‘quantity5’];
$quantity6=$rows[‘quantity6’];
$quantity7=$rows[‘quantity7’];
$quantity8=$rows[‘quantity8’];
$quantity9=$rows[‘quantity9’];
$quantity10=$rows[‘quantity10’];
}
if ($purchase1 == $merchandise){ $total1 == $quantity1; }
if ($purchase2 == $merchandise){ $total2 == $quantity2; }
if ($purchase3 == $merchandise){ $total3 == $quantity3; }
if ($purchase4 == $merchandise){ $total4 == $quantity4; }
if ($purchase5 == $merchandise){ $total5 == $quantity5; }
if ($purchase6 == $merchandise){ $total6 == $quantity6; }
if ($purchase7 == $merchandise){ $total7 == $quantity7; }
if ($purchase8 == $merchandise){ $total8 == $quantity8; }
if ($purchase9 == $merchandise){ $total9 == $quantity9; }
if ($purchase10 == $merchandise){ $total10 == $quantity10; }

$orders = ($total1 + $total2 + $total3 + $total4 + $total5 + $total6 + $total7 + $total8 + $total9 + $total10);

$inventory = ($quantity – $orders);
echo ”
<tr><td>$merchandise</td><td>$inventory</td></tr>”;
}
[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @beylah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...