我想采用一个关联数组并解析它以放入SET
查询的UPDATE
部分:
我使用关联数组调用:
$this->ccQuery( 'emails', array('user_id' => $id, 'email_address' => $request->email) );
function ccQuery( $t, $a, $id=null )
{
foreach($a as $key=>$value)
{
$setfields[] = $key . "='" . $value . "'";
}
$setfields = implode(', ', $setfields);
$testquery2 = 'UPDATE mytable_'.$t.' SET ' .$setfields. ' WHERE user_id="'.$user_id;
...
}
setfields
为空。我做错了什么?
答案 0 :(得分:0)
可能是这样的:
...
$testquery2 = "UPDATE mytable_"
foreach($a as $key=>$value)
{
$testquery2 = $testquery2 ."$t SET '$value' WHERE user_id= '$id'";
}
...