Skip to content

Instantly share code, notes, and snippets.

@Moketronics
Created March 28, 2012 17:15
Show Gist options
  • Save Moketronics/2228349 to your computer and use it in GitHub Desktop.
Save Moketronics/2228349 to your computer and use it in GitHub Desktop.
Check update values against existing to populate array of changes
<?php
$query = 'SELECT tile_name, tile_price, quantity, old_lot_qty, nom_height, nom_width, nom_thick, exact_height, exact_width, box_tile_count, local_supply, rating, tile_notes FROM tiles WHERE tile_id=' . $iTile_id;
$result = mysql_fetch_array(mysql_query($query));
$aTile_changes = array();
$aTile_values = array($sTile_name, $iTile_price, $iQuantity, $iOld_lot_qty, $iNom_height, $iNom_width, $iNom_thick, $iExact_height, $iExact_width, $iBox_tile_count, $iLocal_supply, $iRating, $sTile_notes);
$i = 0;
foreach ($result as $key => $row) {
if ($aTile_values[$i] != $row || (empty($aTile_values[$i]) && $row != '')) {
array_push($aTile_changes, $key => $aTile_values[$i]);
}
$i++
}
$query = "UPDATE tiles SET ";
foreach ($aTile_changes as $key => $row) {
$query .= $key . '=\'' . $row . '\', ';
}
$query = trim($query, ', ');
$query .= " WHERE tile_id = $iTile_id";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment