Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created January 10, 2011 23:22
Show Gist options
  • Save gavinblair/773693 to your computer and use it in GitHub Desktop.
Save gavinblair/773693 to your computer and use it in GitHub Desktop.
lose the last comma off a list
<?php
$sql = "UPDATE coupons SET ";
foreach($args as $key => $arg) {
$arg = $this->db->escape($arg);
$key = $this->db->escape($key);
$sql .= "$key = $arg, ";
}
//lose the last comma
$sql = rtrim($sql, ", ");
$sql .= " WHERE coupon_code = $coupon_code";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment