Welcome Guest, Not a member yet? Register   Sign In
update field modified value in table
#1

[eluser]handoyo[/eluser]
I got codes like this

controller/order

Code:
function edit($no=0)
    {
        if ($this->input->post('id'))
        {
            if (isset($_REQUEST['notif']))
            {
            $this->input->post('status_order');
            $result=$this->MOrder->updateOrder();
            $this->email->from('[email protected]','Admin');
            $this->email->to('[email protected]');
            $this->email->subject('Testing email class');
            $this->email->message('Status order '.$status);
            $this->email->send();
            //return $result;
            $this->session->set_flashdata('message','Berhasil update order');
            redirect('admin/order/index','refresh');
            }
            else
            {
            $this->MOrder->updateOrder();
            $this->session->set_flashdata('message','Berhasil update order');
            redirect('admin/order/index','refresh');
            }
        }
        else
        {
            //$id = $this->uri->segment(4);
            $data['title'] = "Edit Order";
            $data['main'] = 'admin/order_edit';
            $data['order'] = $this->MOrder->getOrder($no);
            $data['status']=$this->MOrder->getStatus();
            if (!count($data['order'])){
                redirect('admin/order/index','refresh');
            }
            $this->load->vars($data);
            $this->load->view('dashboard');
    }
    }

function get($id)
    {
    $id = trim($this->input->post('id'));
    $hasil=$this->MOrder->getOrder($id);
    $array=array('modified'=>$hasil['modified']);
    echo json_encode($array);            
    }

view/order_home
Code:
// wait for the DOM to be loaded
$(document).ready(function()
{
    $("#msg").hide();
    $('#myform').ajaxForm(function()
    {
    var id = $('#id').val();
    $.post("order/get/", { 'id' : id },
     function(data){
     [b]$('#modif').html(data.modified);[/b]
     //alert(data.modified); // John
     //console.log(data.result); //  2pm
     }, "json");
    
        //nampilin di div message string yg ada di dalam html()
    $("#msg").html("Berhasil update order").fadeIn(1500);
    $("#msg").fadeOut(1500);
    });
    

});
<h1>&lt;?php echo $title;?&gt;</h1>
&lt;?php
if ($this->session->flashdata('message')){
    echo "<div class='message' name='msg' id='msg'>".$this->session->flashdata('message')."</div>";
}
echo "<div name='msg' class ='msg' id='msg'></div>";
//echo "<div class='message' name='msg' id='msg'></div>";
echo "<table border='1' cellspacing='0' cellpadding='3' width='600' id='order_home' name='order_home'>\n";
echo "<tr valign='top'>\n";
echo "<th>No Order</th>\n<th>No Cust</th><th>Tgl Pesan</th><th>Modified</th><th>Status</th><th>Update</th><th>Actions</th>\n";
echo "</tr>\n";

if (count($order)){
    foreach ($order as $key => $list){
        echo "<tr valign='top'>\n";
        echo "<td>".anchor("admin/order/detail/".$list['no_order'],$list['no_order'])."</td>\n";
        echo "<td>".$list['custid']."</td>\n";
        $datetime = strtotime($list['tgl_pesan']);
        $orderdate = date("d-m-y H:i ", $datetime);
        echo "<td>".$orderdate."</td>\n";
        $modifieddate = strtotime($list['modified']);
        $modified = date("d-m-y H:i ", $modifieddate);
        [b]echo "<td id='modif' name='modif'>".$modified."</td>\n";[/b]
        $attributes = array('id' => 'myform');
        echo form_open('admin/order/edit',$attributes);
        echo "<td align='center'>".form_dropdown('status',$status,$list['status'])."</td>\n";
        echo '&lt;input type="hidden" id="id" name="id" value="'.$list['id'].'" /&gt;';
        //echo form_hidden('id',$list['id']);
        echo form_hidden('status_order',$list['status']);
        $data = array('name'=>'notif','id'=>'notif');
        $button=array('name'=>'submit','id'=>'submit_button','value'=>'Update');
        echo "<td align='center'>".form_checkbox($data)."<label for='update'>Notifikasi cust</label>".form_submit($button)."</td>\n";
        echo "<td align='center'>";
        //echo anchor('admin/kategori/edit/'.$list['id'],'edit');
        echo anchor("admin/order/edit/".$list['no_order'],img(base_url().'/images/edit.jpg'));
        echo " | ";
        //echo anchor('admin/kategori/delete/'.$list['id'],'delete');
        echo anchor("admin/order/delete/".$list['no_order'],img(base_url().'/images/delete.jpg'));
        echo "</td>\n";
        echo "</tr>\n";
        echo form_close();
    }
    
}
echo "</table>";
?&gt;

I'm trying to change the value on modif as i update the data.I use json,but i can't get it worked as it should be..By the way,this is my testing site

7com

username : admin
password : admin

The problem is in the order page..Thanks a lot guys..
#2

[eluser]@rno[/eluser]
Hi!

First problem I see is that you have a loop (for each) creating forms where all modif elements have the same id. This is not allowed in proper XHTML and your jQuery code will not be able to find the correct element in your code.

You could read some jQuery docs about finding the element as a child of the form... I think that would be the easiest way to get this done.

Good luck,
Arno
#3

[eluser]handoyo[/eluser]
Hi Arno,i got the idea from virtuemart where there are checkbox in each row,so i thought it was done by using form in each row...Maybe using form array should work?Thanks...
#4

[eluser]@rno[/eluser]
Hi handoyo,

Using a form in each row isn't really the problem here I think. It's more that there are multiple elements sharing the same ID wich causes jQuery to return an array when calling $('#modif') and thus you cannot use the html() function.

Hope this helps.

Regards,
Arno
#5

[eluser]handoyo[/eluser]
What if i make the modif as an array?Thanks...
#6

[eluser]@rno[/eluser]
Sure, that would be no problem.
You can have one large form on the page with the complete table in an array, specifying a unique ID on all elements in it based on the current row / column.

Regards,
Arno
#7

[eluser]handoyo[/eluser]
I've tried to make the modif td as an array,it still doesn't works.. ^_^
#8

[eluser]@rno[/eluser]
Looking at your viewers code again you should definitely restructure your code.
The HTML outputted now is NOT compliant to any standard. Your from tag should never start in between td's nor should it span multiple td's and tr's if it's not spanning the complete table.

I'd consider something like:
Code:
&lt;form&gt;
    &lt;?php
    $i = 0;
    foreach ($order as $key =&gt; $list)
    {
    ?&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td&gt;
                &lt;?php /* PUT OTHER DATA IN THERE COLUMNS */ ?&gt;
            &lt;/td&gt;
            &lt;td id="modif_&lt;?php echo $i;?&gt;"&gt;
                &lt;?php /* YOUR UPDATES CAN GO HERE */ ?&gt;
            &lt;/td&gt;
            &lt;td&gt;
                Button calling javascript with $i as Row number
            &lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
    &lt;?php
        $i++;
    }
    ?&gt;
&lt;/form&gt;

As long as a call to the controller knows from which row it came you can update the correct row accordingly after a response from the controller.

Regards,
Arno
#9

[eluser]handoyo[/eluser]
Thanks Arno,i'll try it first.. By the way do you mean that i should put
Code:
echo form_open('admin/order/edit',$attributes);
echo "<td align='center'>".form_dropdown('status',$status,$list['status'])."</td>\n";
echo '&lt;input type="hidden" id="id" name="id" value="'.$list['id'].'" /&gt;';
echo form_hidden('status_order',$list['status']);
$data = array('name'=>'notif','id'=>'notif');

in

Code:
&lt;?php /* YOUR UPDATES CAN GO HERE */ ?&gt;
#10

[eluser]@rno[/eluser]
No, the form_open() function shoud precede the opening of the table.
In my example code your complete table is wrapped inside a single form.

You should just put the controls (buttons, dropdowns etc) inside a the td where I stated: Your code goes here.

Regards,
Arno

EDIT:
Forgot to mention:

Code:
&lt;?php /* YOUR UPDATES CAN GO HERE */ ?&gt;

Will be used like: $('#modif_'+i).html(data.modified);




Theme © iAndrew 2016 - Forum software by © MyBB