Reseller Domain Murah dan termurah di Indonesia? ya di ResellerCamp.
         
 

Forum PHP Indonesia

 
Advanced Search
   
 
Home Register FAQ Memberlist Usergroups  
 
 

Forum PHP Indonesia Forum Index PHP Help mengisi nomor urut dari tabel yg udah ada isinya
Display posts from previous:   
      All times are GMT + 7 Hours  

mengisi nomor urut dari tabel yg udah ada isinya

Post new topic  Reply to topic

Tue Feb 09, 2010 17:41
Author Message
allrightjack
PHPuser
PHPuser


Joined: 10 Mar 2009
Posts: 26
Location: batavia

Post subject: mengisi nomor urut dari tabel yg udah ada isinya Reply with quote

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.
 
View user's profile Send private message
      Back To Top  

Tue Feb 09, 2010 17:57
Author Message
vank
Jagoan PHP
Jagoan PHP


Joined: 31 Mar 2009
Posts: 557

Post subject: Reply with quote

bikin primary key baru aja, set ke autoincrement...
_________________
 
View user's profile Send private message
      Back To Top  

Wed Feb 10, 2010 07:36
Author Message
allrightjack
PHPuser
PHPuser


Joined: 10 Mar 2009
Posts: 26
Location: batavia

Post subject: Reply with quote

waaahhh, mas vank emang jagoan PHP. thank you very much! hail
 
View user's profile Send private message
      Back To Top  

Wed Feb 10, 2010 09:14
Author Message
esraldi
PHP Programmer
PHP Programmer


Joined: 15 Jun 2008
Posts: 168
Location: yogyakarta

Post subject: Reply with quote

allrightjack wrote:
waaahhh, mas vank emang jagoan PHP. thank you very much! hail


Hebat sekali sampai program bro sampai penggunaan autoincrement di db kelupaan quit Cool Man
_________________
esraldi
 
View user's profile Send private message Send e-mail
      Back To Top  
Post new topic  Reply to topic

 
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


      Back To Top  

Page 1 of 1
Jump to:  
Powered by phpBB © 2001, 2002 phpBB Group
Avalanche style by What Is Real © 2004