-->

Notification

×

Iklan

Iklan

Indeks Berita

Tag Terpopuler

Menampilkan data berdasarkan pilihan di listbox pada PHP

Wednesday, February 6, 2013 | Wednesday, February 06, 2013 WIB Last Updated 2013-02-13T11:18:24Z

Assalamualaikum...
Kali ini IT Sasak akan share tentang cara menampilkan data berdasaarkan pilihan di Listbox,,,
Ilmu dan Tutorial ini saya peroleh dari blog tetangga... ^_^
Sangat bermanfaat sekali,,, jadi ta putuskan untuk di share disini juga,,, hihihi



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
}
?>



Sumber : ri32.wordpress.com