I've a problem with an mysql update query. My code is:
public function update($idp, $ids){
$sql = "UPDATE table SET idp = ? WHERE ids = ?";
$atmt = $this->db->prepare($sql);
$atmt->bindParam(1, $idp, PDO::PARAM_INT);
$atmt->bindParam(2, $ids, PDO::PARAM_INT);
$atmt->execute();
return 1;
}
My array of data is:
[0]=>
array(2) {
["id_s"]=>
int(2)
["id_p"]=>
int(111)
}
[1]=>
array(2) {
["id_s"]=>
int(3)
["id_p"]=>
int(175)
}
[2]=>
array(2) {
["id_s"]=>
int(5)
["id_p"]=>
int(25)
}
[3]=>
array(2) {
["id_s"]=>
int(7)
["id_p"]=>
int(127)
}
...
Walk on the array's elements and call the update method:
foreach($array as $index => $val){
$idp = $id[$index]['id_p'];
$ids = $id[$index]['id_s'];
$admin->update($idp, $ids);
}
I'd like to have a table like tihs:
ids | idp | other column
1 5 ...
3 97 ...
3 97 ...
4 32 ...
5 178 ...
5 178 ...
5 178 ...
...
However with the foreach loop I update only the first record; the array is ok with all values, it seem like the bind of parameters don't work. Any solution? Thanks!