I has been read this topic Constructing UPDATE statements using associative arrays in PHP , but it was a bit different with what I need to.
I have a table t1
.
+--------------+----------------+----------------+------------+
| money | exp | uid | remark |
+--------------+----------------+----------------+------------+
| 9999 | 9999 | 1 | |
| 1234 | 567 | 2 | |
| 8887 | 88 | 3 | |
+--------------+----------------+----------------+------------+
I would like to create a PHP function
called jnupdateuser
to update this table, like:
jnupdateuser(array('money'=>10000,'exp'=>10000),1);
After that the data will be this:
+--------------+----------------+----------------+------------+
| money | exp | uid | remark |
+--------------+----------------+----------------+------------+
| 10000 | 10000 | 1 | |
| 1234 | 567 | 2 | |
| 8887 | 88 | 3 | |
+--------------+----------------+----------------+------------+
If do with this:
jnupdateuser(array('remark'=>'None'),2);
than the data will be this:
+--------------+----------------+----------------+------------+
| money | exp | uid | remark |
+--------------+----------------+----------------+------------+
| 9999 | 9999 | 1 | |
| 1234 | 567 | 2 | None |
| 8887 | 88 | 3 | |
+--------------+----------------+----------------+------------+
My code as below:
function jnupdateuser($jnparams = array(),$uids){
$conditionStrings = array();
foreach ($jnparams as $column => $value) {
//how to create this part to update my table? or maybe I was totally wrong?
}
return DB::query("UPDATE ".DB::table('game_jnmx_user')." SET ??? = ??? WHERE uid = $uids ");
}
DB::query
is my template language, same as mysqli_query
, DB::table
also template language;
Thank you.