Welcome Guest, Not a member yet? Register   Sign In
Issue with database record updating: updating record inside a foreach loop?
#11

[eluser]Salvatore Formisano[/eluser]
not sure how I could get it for you mate, it's all js powered at the minute, meaning I have no landing page once the thing has finished. let me past some code though:

the reorder_photos method in the photos controller
Code:
function reorder_photos()
{
    foreach($_POST as $key=>$value){
        $data['position']=$this->input->post($key);
        $this->m__crud->update_record("photos",$key,$data);
    }
}

the reorder_photos js function, triggered every time the user drags and drops photos from the list
Code:
function reorder_photos(){
    var form_data="";
    $(".reorder .gallery").each(function(pos,el){
        p_id=$(this).attr("id").substring(1,100);
        p_pos=pos+1;
        form_data=form_data+"&"+p_id+"="+p_pos;
    });
    form_data=form_data.substring(1,100);
    $.post('<?php echo site_url('admin/photos/reorder_photos');?>',form_data,function(res){
        alert("done")
    });
}

so basically, I have this amin panel with a list of draggable photos, and if the user wants to change the picture's order, all he has to do is literally grab them and move them (using jquery ui).

the reorder_photos js function will trigger and then send the form_data string to the reorder_photos method in the photos controller, which SHOULD then do his job.

the method is able to return a json containing all the data it received, but for some reason it can't put that same data in the database.


THAT is why I believe my error lies in the synthax, or in some bad concept. Who knows!


Messages In This Thread
Issue with database record updating: updating record inside a foreach loop? - by El Forum - 12-16-2009, 06:07 AM



Theme © iAndrew 2016 - Forum software by © MyBB