Make your input for the quantity have a name like: quantity[$id], i.e.:
<input type="text" name="quatity[<?php echo $id; ?>]" value="<?php echo $quantity; ?>" />
Then in your php, just see if quantity is not empty:
if(!empty($_POST['quantity'])) {
And finally, you can just loop through them and run an update statement that only updates if the quantity is different :
if(!emtpy($_POST['quantity']))
{
foreach($_POST['quantity'] as $id=>$qnty)
{
// Update all rows only when the quantity in the DB is different from the quantity submitted
$sql = "UPDATE `table` SET `quantity` = '$qnty' WHERE `id`='$id' AND `quantity` != '$qnty'";
// Execute the sql query....
}
}
Hope that helps.