| |
Forum PHP IndonesiaDapatkan pertolongan pertama pada kebingungan PHP dan sekitarnya |
|
|
|
|
|
| |
|
|
All times are GMT + 7 Hours
|
|
mengisi nomor urut dari tabel yg udah ada isinya
 |
Tue Feb 09, 2010 17:41 |
 |
Author |
Message |
allrightjack PHPuser

Joined: 10 Mar 2009 Posts: 26 Location: batavia
|
| Post subject: mengisi nomor urut dari tabel yg udah ada isinya |
|
|
begini kawan2,
saya punya tabel yang berisi 30 record. saya menambahkan sebuah field 'NoUrut' yg bertipe integer. agar tidak mengisi field tsb satu persatu, saya pake program sbb:
| Code: | <?php $koneksi = mysql_connect("localhost", "root","passwd");
$pilih = mysql_select_db("dbase", $koneksi);
$query = "SELECT * FROM table1";
$result = mysql_query($query);
if (!$result) {
die('Query failed: ' . mysql_error());
}
/* fetch rows in reverse order */
for ($i = mysql_num_rows($result) - 1; $i >= 1; $i--) {
if (!mysql_data_seek($result, $i)) {
echo "Cannot seek to row $i: " . mysql_error() . "\n";
continue;
}
if (!($row = mysql_fetch_assoc($result))) {
continue;
}
//update disini
$q="update table1 set NoUrut='$i' LIMIT $i";
$exe=mysql_query($q) or die(mysql_error());
}
mysql_free_result($result); ?> |
dengan koding tsb field NoUrut terisi dari 1 sampai 30. nah, sekarang ada tabel yang sudah berisi ribuan record. saya coba koding diatas, namun prosesnya lama sekali sampe akhirnya saya batalkan.
ada cara lain ga untuk otomatis isi NoUrut?
thx. |
|
| |
|
|
 |
Tue Feb 09, 2010 17:57 |
 |
Author |
Message |
vank Jagoan PHP


Joined: 31 Mar 2009 Posts: 557
|
| Post subject: |
|
|
bikin primary key baru aja, set ke autoincrement... _________________
 |
|
| |
|
|
 |
Wed Feb 10, 2010 07:36 |
 |
Author |
Message |
allrightjack PHPuser

Joined: 10 Mar 2009 Posts: 26 Location: batavia
|
| Post subject: |
|
|
waaahhh, mas vank emang jagoan PHP. thank you very much!  |
|
| |
|
|
 |
Wed Feb 10, 2010 09:14 |
 |
Author |
Message |
esraldi PHP Programmer

Joined: 15 Jun 2008 Posts: 168 Location: yogyakarta
|
| Post subject: |
|
|
| allrightjack wrote: | waaahhh, mas vank emang jagoan PHP. thank you very much!  |
Hebat sekali sampai program bro sampai penggunaan autoincrement di db kelupaan  _________________ esraldi |
|
| |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|
|
|
|
|
Powered by phpBB © 2001, 2002 phpBB Group
|
|
|
|
|
|
|
|
| |
|
|
|
|
|
|