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 Lanjut

http://dropdown-check-list.googlecode.com/files/dropdown-check-list.1.2qa.zip


Depok, 25-01-2011

noname

About these ads

28 Responses

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

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 478 other followers

%d bloggers like this: