Hi all,i got codes like this

$(document).ready(function()
{
$ ( "#msg").hide();
$ ( '#myform').ajaxForm(function()
{
$ .post("getOrder/", { 'id' : id },
function(data)
{
console.log(id);
$ ( '#modif').html(data.modified);
}, "json");
$ ( "#msg").html("Berhasil update order").fadeIn(1500);
$ ( "#msg").fadeOut(1500);
});
});

< ? php
echo "< div name='msg' class ='msg' id='msg'></ div>";
echo "< table border='1' cellspacing='0' cellpadding='3' width='100%' 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>id</ th>< th>Actions</ th>\n"; echo "</ tr>\n"; if (count($order)) {
foreach ($order as $key => $list)
{
echo form open('admin/order/edit',$attributes);
echo < td align='center'>".form
dropdown('status',$status,$list['status'])."\n";
'echo input type="hidden" id="id" name="id" value="'.$list['id'].'" />';
$data = array('name'=>'notif','id'=>'notif');
echo "< td align='center'>".form checkbox($data). "
echo "< label for='update'>Notifikasi cust ".form
submit('submit','Update')."\n";
echo form_ close(); }
}
?>

I try using 2 rows,when i check by using firebug and upon i click the second row update button,it return id=1 instead of 2.What should i do?Are there any mistakes in my codes?Thanks a lot... ^_^

Issue

  • Just as a note, using a template or templating system is a must, separates your business logic and your display logic, will make bugs much more transparent. Tchalvak about 7 years ago

1 answer

1
point

Hmmm, I'd guess that you're you're counting your array with ordinal numbers, i.e. starting with 0, 1, 2, 3, 4 instead of 1, 2, 3, 4, 5.

So perhaps just instead of:

'echo input type="hidden" id="id" name="id" value="'.$list['id'].'" />'; 

make it:

'echo input type="hidden" id="id" name="id" value="'.($list['id']+1).'" />'; 

Also, If I were you, I'd avoid using just "id" as an identifier, since that name is vague (css id, the many different ids you need to use in a relational database, etc).

Answered about 7 years ago by Tchalvak
  • Thanks Tchalvak..I'll try it first... handoyo about 7 years ago
  • Hi,i've tried it.Yet it doesn't work..Also i changed the id="id" to id="no_id".. Thanks a lot... handoyo about 7 years ago