Select rows from database fields based on form submit array

The end result is to get the $duty which is the $rate percentage of the $cost. so the user is also inputting the cost and the categories and some other information i get all of those in the for each loop off of the POST and they line up in the right order. I am getting the categories and the rate from the query but i still need to get the rate to line up with the inputted $cost POST to get the $duty. something like this below.

$duty = $rate / 100 * $cost

$qty $pcategories $cost $pfrom $rate $duty
1 Bicycles 100 ThisStore 45
7 Auto Parts 200 ThatStore 60
5 Alarm Systems 300 OtherStore 35

But where the row for the rate is not in the same order as the row for the cost the duty values are coming out wrong.

Just for anyone who may have been following. I ended up using an ORDER BY clause that did the trick. Example Below

<?php $sql = "SELECT `categories`, `rate` FROM `lt_products` WHERE `categories` IN ('".implode("','",$pcategories)."') ORDER BY FIELD(categories, '".implode("','",$pcategories)."')"; $result = mysql_query($sql)or die(mysql_error()); while($row = mysql_fetch_assoc($result)) { ?>

Thanks for the Help

Sponsor our Newsletter | Privacy Policy | Terms of Service