[eluser]Salvatore Formisano[/eluser]
Hey everone,
I'll try to be quick, I am trying to use a foreach loop to parse a $_POST coming from javascript to reorder a few elements in a database table.
Here's the code:
Code:
function reorder_photos()
{
foreach($_POST as $key=>$value){
$data['position']=$value;
$this->m__crud->update_record("photos",$key,$data);
}
}
the update_record method from the m__crud model it quite straightforward:
Code:
function update_record($table,$id,$data)
{
$this->db->where('id',$id);
$this->db->update($table,$data);
}
so basically, I have a string like this one 354=1&564=2&999=3 (photo with id of 354=position 1 & photo with id of 564= position 2 & ...)
The string is then sent as $_POST the reorder_photos method.
The data is fine (I formed an array with php and printed it back as json through an alert).
also (just in case...) I tried this outside of the loop
Code:
$data['position']="1";
$this->m__crud->update_record("photos","354",$data);
and it worked, updating the record with an id of 354 setting the position to 1.
Is the record update not allowed inside a foreach?
Many thanks,
Salvatore