Re: Conditional updating...
| From: | J R | Date: | Wed, 28 Jun 2006 06:56:51 +0000 |
| Subject: | Re: Conditional updating... | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-42122@lists.php.net to get a copy of this message | ||
try this one.
just pass for $_value an array with your table fieldname as your key
function constructUpdate( $_tbl_name, $_where, $_values )
{
$valstr = '';
$firstval = false;
if (is_array($_values)) {
foreach( $_values as $key=>$val ) {
if ($val != '') {
if( $firstval )
$valstr.= ',';
if (is_string($val)) {
$valstr.= " $key = '$val'";
} else {
$valstr.= " $key = $val";
}
$firstval = true;
}
}
} else {
$valstr = $_values;
}
$retStr = "update $_tbl_name set $valstr";
if( $_where )
$retStr.= " where $_where";
return $retStr;}