Jump to content

Populate html table based on selected dropdown value


afdoal

Recommended Posts

hi,,,

i need question about populate table based on dropdown 

 

this my php file 

kecamatan.php

<?php
	require 'config_db.php';
	$self='kelurahan.php';
	
	if (isset($_POST['action'])&&$_POST['action']=='edit'){
		$namakelurahan = _post('namakelurahan');
		if ($namakelurahan==''){
			r2($self,'e','Nama kelurahan tidak boleh kosong');
		}
		$id = _post('id');
		$grp = ORM::for_table('kelurahan')->find_one($id);
		$grp->set('namakelurahan', $namakelurahan);
		$grp->save(); 
		r2($self,'s','Perubahan data berhasil di lakukan');
	}
	elseif (isset($_POST['action'])&&$_POST['action']=='delete'){
    	$trid = _post('trid');
  		$tr = ORM::for_table('kelurahan')->find_one($trid);
  		if (!$tr){
 			r2($self,'e','Nama kelurahan tidak di temukan');
  		}
    	$tr->delete();
		r2($self,'s','Data berhasil di hapus');    
    
	}
	elseif (isset($_POST['action'])&&$_POST['action']=='add'){
		$namakelurahan = _post('kelurahan'); 
		if ($namakelurahan==''){
			r2($self,'e','Nama kelurahan wajib diisi');
		}
		$grp = ORM::for_table('kelurahan')->create();
		$grp->namakelurahan=$namakelurahan;
		$grp->save();  
		r2($self,'s','kelurahan berhasil disimpan');  
    }
	else {?>
<?php
	$query ="SELECT * from kecamatan";
	$stmt = $dbh->prepare("$query");
	$stmt->execute();
	$reskecamatan = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
		<title><?php echo 'Sistem Informasi Surveilans' // lc('WebsiteTitle'); ?></title>
		<link rel="shortcut icon" type="image/x-icon" href="../assets/img/favicon.ico">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<link type='text/css' href='views/bmsapp/css/cstyle.css' rel='stylesheet' />
		<link href="../assets/css/bootstrap.min.css" rel="stylesheet">
		<link href="../assets/css/bootstrap-responsive.min.css" rel="stylesheet">
		<link href="../assets/css/clientstyle.css" rel="stylesheet">
		<link href="../assets/css/common.css" rel="stylesheet" type="text/css" />


</head>

<body style='background-color: #FBFBFB;'>
	<div id='main-container'>
		<div class='header'>
			<div class="header-box wrapper">
				<div class="hd-logo"><a href="#"><img src="../assets/uploads/logo.png" alt="Logo"/></a></div>
			</div>
		</div>
		<div class="navbar">
			<?php include 'menu.php';?>
		</div>
		
		<div class="container-fluid">	
			<div class="row-fluid">
				<div class="span12">
					<h3>Data kelurahan</h6>
					<table>
						<tr>
							<td>
								Kecamatan : 
								<select onchange="">
									<option value="-1">Semua Kecamatan</option>
									<?php
										foreach($reskecamatan as $allkecamatan) {
										$id = $allkecamatan['id'];
										$namakecamatan = $allkecamatan['namakecamatan'];
									?>

									<option value="<?php echo $allkecamatan['id']?> "> <?php echo $allkecamatan['namakecamatan']; ?>
									</option>
									<?php } ?>
							</select>
							</td>
						</tr>
					</table>
					<table class="table table-bordered table-striped table-hover">
						
						<tr>
							<th scope="col">No</th>
							<th scope="col" style="display:none;">Id kelurahan</th>
							<th scope="col">Nama kelurahan</th>	
							<th scope="col">Nama Kecamatan</th>	
							
							<th scope="col">Olah Data <img id="ajxspin" src='../assets/img/blue_spinner.gif'/></th>	
						</tr>
						<?php

							$query ="SELECT kelurahan.id, kelurahan.idkecamatan, kecamatan.namakecamatan, kelurahan.namakelurahan
									FROM kecamatan INNER JOIN kelurahan ON kelurahan.idkecamatan = kecamatan.id";
							$stmt = $dbh->prepare("$query");
							$stmt->execute();
							$result = $stmt->fetchAll();
							$i='0';
    							foreach($result as $accgroup) {
									$i++;				
								$id = $accgroup['id'];
								$namakelurahan = $accgroup['namakelurahan'];
								$namakecamatan = $accgroup['namakecamatan'];

								echo "<tr>
									<td>$i</td>
									<td style=\"display:none;\">$id</td>
									<td>$namakelurahan</td>
									<td>$namakecamatan</td>
									<td><a href=\"kelurahan.edit.php?_cmd=$id\" data-toggle=\"modal\"><i class=\"icon-pencil\"></i></a> 
									<a href=\"kelurahan.delete.php?_cmd=$id\" data-toggle=\"modal\"><i class=\"icon-remove\"></i></a></td>
									</tr>";}
						
						?>

						
						<tr>
							<!--td colspan="3"><a class="btn btn-inverse" href="my-tickets.php"><?php echo 'view' ?> <?php echo 'all_support_tickets' ?></a> <a class="btn btn-primary" href="create-ticket.php"><?php echo 'new_ticket' ?></a></td-->
							<td colspan="4">
								<a class="btn btn-inverse" href="kelurahan.add.php" data-toggle="modal" ><i class="icon-plus icon-white"></i>Tambah Data</a>
								<a class="btn btn-primary" href="kelurahan.lap.php"><i class="icon-list icon-white"></i>Laporan</a>
							</td>
						</tr>
					</table>
				</div>
				</div>
			</div>
		</div>
	</div>
	<div class="footer"><?php echo $footerTxt; ?><br /><br /></div>
	
	
</body>
</html>


<?php }
?>

and this output my code in browser:

 

 

2014-03-28_161054.png

 

 

 

and my question, how to populate the table based on selected dropdown value?

 
if user select Kecamatan - Ampenan, the table just show all kelurahan from kecamatan ampenan

 

sorry my english is bad 

 

thanks b4

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.