Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
PHPmaster PHPmaster is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 332
Rep Power: 15
PHPmaster mempunyai hidup yang Normal
Default [SQL] Cara ambil data dari tabel secara acak?

Halo agan2 semua,

To the point aja ya, ane mau tanya dong gimana cara kita ngambil data dari tabel tapi secara acak?



Misal, tabel 'murid':

id | nama

1 | ayu

2 | budi

3 | edi



id -> PK





Ane pake php & mysql, cara ane sih gini:


PHP Code:




$jumlah_id = mysql_query("SELECT * FROM `murid`; ");

$id = rand(1, $jumlah_id);

$data = mysql_query("SELECT * FROM `murid` WHERE `id`='" . $id . "' ; ");







Tapi ada kelemahannya, kalo row $id kosong (misalnya terhapus), nanti semuanya jadi error.. Apa ada cara yg lbh baik?



Mohon bimbingannya gan

</div>
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Terkait
Thread Thread Starter Forum Replies Last Post
[ASK] Software buat ambil image secara langsung dari image hosting KernelZero Shareware & Freeware 0 24th October 2012 02:24 PM
[C# .NET] - Cara edit data di DataGridView dari 2 tabel yg berbeda Badguy13 Programming 0 20th November 2011 01:09 AM
[ask]mindahin isi stok barang dari tabel stok1 ke tabel stok2 vb6 database ms.access Badguy13 Programming 0 20th November 2011 01:05 AM
[C# .NET] - Cara edit data di DataGridView dari 2 tabel yg berbeda Braincode Programming 0 11th November 2011 02:01 PM

 


All times are GMT +7. The time now is 10:32 AM.