Saya mempunyai data di database (tbl_rute) seperti berikut:
________________________
| ID | Kd_Try | Rute |
|
|
| 01 | Try001 | rute A |
| 02 | Try002 | rute B |
| 03 | Try003 | rute C |
| 04 | Try004 | rute D |
| 05 | Try005 | rute E |
Desain Form saya:
_________________________________
| ID | Rute | Option | Option |
|
| 01 | rute A | Update | Delete |
| 02 | rute B | Update | Delete |
| 03 | rute C | Update | Delete |
| 04 | rute D | Update | Delete |
| 05 | rute E | Update | Delete |
Option Update atau Delete berupa link untuk update atau delete data berdasarkan ID...
Yang saya tanyakan:
Bagaimana cara mengurutkan kembali ID tersebut apabila ID 02 didelete...
Supaya hasilnya seperti ini:
_________________________________
| ID | Rute | Option | Option |
|
| 01 | rute A | Update | Delete |
| 02 | rute C | Update | Delete |
| 03 | rute D | Update | Delete |
| 04 | rute E | Update | Delete |
Coding PHP untuk ID:
<?php
$kd_try = $_POST['kd']; //text field name kd
$addRute = $_POST['rute']; //text field name rute
$query1 = mysql_query("SELECT max(id) AS last FROM tbl_rute WHERE kd_try LIKE
'$kd_try'");
$data = mysql_fetch_array(query1);
$lastNoID = $data['last'];
$lastNoUrut = substr($lastNoID, 0, 2);
$nextNoUrut = $lastNoUrut + 1;
$nextNoID = sprintf('%02s', $nextNoUrut);
$sql = mysql_query("insert into tbl_rute(id, kd_try, rute) values
('$nextNoID','$kd_try', '$addRute')");
?>
Mohon Bantuannya...
*Terima Kasih*