Menampilkan data berdasarkan pilihan di listbox pada PHP


Ada teman saya mas kaka yang bertanya :

Bagaiamana caranya menampilkan data berdasarkan pilihan yg ada di listbox. bagaiamana caranya menampilkan data berdasarkan pilihan yg ada di listbox. Misalnya di list box itu berdasarkan nama_staff. mohon bantuannya, saya lagi buat TA. terimakasih

Alur Program :

  1. Buat koneksi ke database
  2. Buat Form
  3. Fungsi javascript
  4. Proses tampilkan data

Script Koneksi

<?php
$host=”localhost”;
$user=”root”;
$pass=””;
$db=”test”;
//koneksi
$koneksi=mysql_connect($host,$user,$pass);
mysql_select_db($db,$koneksi);
?>

Potongan Script Form

<td width=”241″>
<select multiple=”multiple” name=”id” id=”id” onChange=”pilih(this.value)”>
<?php
$query_limit=mysql_query(“select * from guestbook“);
while($row=mysql_fetch_array($query_limit))
{
?><option value=”<?php  echo $row[‘id_gb’]; ?>”><?php  echo $row[‘nama’]; ?></option><?php
}
?>
</select>
</td>
<td width=”195″ valign=”top”>
<select name=”id” id=”id” onChange=”pilih(this.value)“>
<option value=”0″ selected=”selected”>Pilih Nama</option>
<?php
$query_limit=mysql_query(“select * from guestbook”);
while($row=mysql_fetch_array($query_limit))
{
?><option value=”<?php  echo $row[‘id_gb’]; ?>”><?php  echo $row[‘nama’]; ?></option><?php
}
?>
</select>
</td>

Fungsi Javascript

<script languange=”Javascript1.2″>
function pilih(id){
location.replace(“list-ri32.php?id=”+id);
}
</script>

Script menampilkan data

<?php
include “conn.php”;
if($_GET[”]!==””){
$id=$_GET[‘id’];
$query=mysql_query(“select * from guestbook where id_gb=’$id'”);
?>
<table border=”1″>
<tr><th>No</th><th>Nama</th><th>Email</th><th>Pesan</th></tr>
<?php
while($row=mysql_fetch_array($query)){
?>
<tr><td><?php echo $c=$c+1;?></td><td><?php echo $row[‘nama’];?></td><td><?php echo $row[’email’]; ?></td><td><?php echo $row[‘pesan’]; ?></td></tr>
<?php
}
?></table><?php
}
?>

Download

http://www.4shared.com/file/9EmUx_MU/listbox.html

Download Tabel

http://www.4shared.com/file/qfhiRDTt/guestbooksql.html

Sekian artikel dari saya semoga bermanfaat untuk teman-teman dan anda semua…amin

Referensi Buku :

Info Hosting Domain Murah Berkualitas :

  1. Cara-mendaftarkan-domain-sekolah
  2. Tips-memilih-hosting-domain
  3. Penyedia-jasa-hosting-domain-murah
  4. Alasan-mengapa-memilih-idwebhost
  5. Profil-singkat-mengenai-idwebhost

Depok, 25-01-2011

noname

About these ads

32 Responses

  1. syukron kang, makasih banget , lantaran materi dari agan, sy jdi faham source code nya :)

    Like

  2. Gan, kalo melalui tombol submit proses ny.. gmna buat syntax ny ?? Mohon bntuan ny mas..
    Trma kasih.. :)

    Like

  3. Mas , bagaimana caranya insert multiple dengan multiple combo dari database, contoh
    No.Nama Tanggal Agama Tempat lahir
    1. Input text Input Text Combobox Combobox
    2. Input text Input Text Combobox Combobox

    Demikian

    Like

  4. aku mau tanya nih kalo mau menampilkan di script edit tapi data dari database trus tampilnya di script edit dalam bentuk list button? itu gmana ya script nya

    Like

  5. How old your site, or domain name, is will play a role in your overall rankings.
    In simple terms, if you are sharing content through Google+ on a
    daily basis, even Google will give you preference and
    increase your search engine rankings. The main part of search
    engine optimization is keyword research, which is also an important activity of
    SEO companies.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 591 other followers

%d bloggers like this: