Gan semua... ane mau tanya ini...
Cara menampilkan data di database dengan syarat session...
Pertama ane bisa gan, setelah membuat fungsi yang lain gagal...
jadi ini session ane gan
Spoiler for Session :
Code:
<?php
ob_start();
include_once "php/config-db.php";
include_once "php/function_riski.php";
$username = $_POST['username'];
$password = md5($_POST['password']);
$username = stripcslashes($username);
$password = stripcslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);
session_start();
if (empty($_POST["vercode"])){
?> [removed] alert ("Anda harus mengisi kode captcha ");
[removed]="index.php";[removed] <?php
}elseif ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') {
?>
[removed] alert ("kode captcha salah silakan login kembali");
[removed]="index.php";[removed]
<?php
} else {
if (empty($username) || empty($password)){?>
[removed] alert("Username dan Password tidak boleh kosong ");
[removed]="index.php";[removed]
<?php }else{
$query = mysql_query("select * from userlog where username='$username' and password ='$password'");
$cek=mysql_num_rows($query);
$ambil = mysql_fetch_array($query);
if ($cek==1){
$_SESSION['username']= $username;
$_SESSION['password']= $password;
$_SESSION['id_user'] = $ambil['id_user'];
$_SESSION ['loggedin'] = 1;
if ($ambil['hak_akses']=="1"){
header ('location:home1.php');
}
}if($ambil['hak_akses']=="2"){
$query2 = mysql_query("select * from tb_biodatart where nomer_RT = '$username'")
or die(mysql_error());
while($data = mysql_fetch_array($query2)) {
$_SESSION ['nomer_RT'] = $data ['nomer_RT'];
$_SESSION ['nama_lengkap'] = $data ['nama_lengkap'];
$_SESSION ['alamat_lengkap'] = $data ['alamat_lengkap'];
$_SESSION ['nope_rt'] = $data ['nope_rt'];
$_SESSION ['No_KTP'] = $data ['No_KTP'];
$query3 = mysql_query("select * from za_alternatif where no_RT = '$username'")
or die(mysql_error());
while($data = mysql_fetch_array($query3)) {
$_SESSION ['no_RT'] = $data ['no_RT'];
$_SESSION ['No_KTP'] = $data ['No_KTP'];
$_SESSION ['Nama'] = $data ['Nama'];
$_SESSION ['Alamat'] = $data ['Alamat'];
$_SESSION ['Jenis_Kelamin'] = $data ['Jenis_Kelamin'];
header ('location:home2.php');
}}
}else{?>
[removed]alert("username dan password anda salah");
[removed]="index.php";
[removed]
<?php }
}
}
ob_end_flush();
?>
Terus untuk $query2 ane berhasil munculin informasi biodata di database sesuai dengan nomer_RT
Berikut tampilan berhasilnya gan...
Spoiler for Tampilan Session Berhasil :
Berhasil gan... di sini usernya bisa muncul sesuai dengan biodata loginnya
dan ini codenya
Spoiler for Coding Menampilkan data Session Berhasil :
Code:
<section id="main-content">
<section class="wrapper">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header"><i class="fa fa-file-text-o"></i>Alternatif</h3>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i><a href="index.html">Home</a></li>
<li><i class="icon_document_alt"></i>Alternatif</li>
</ol>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Form Alternatif</div><br>
<div class="panel-body">
<form method="POST" action="" class="form-horizontal" autocomplete="off" enctype="multipart/form-data">
<div class="mainjadwal">
<h1 style="margin-left: 50px; margin-bottom: 25px;">Detail Biodata Pekerja</h1>
<form class="form-horizontal" action="?" method="post">
<div class="form-group">
<label class="col-md-2 control-label">Nomer RT :</label>
<div class="col-md-3"><p class="form-control-static" ><?php echo $_SESSION['nomer_RT']; ?></p></div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Nama Lengkap Ketua RT :</label>
<div class="col-md-3"><p class="form-control-static" ><?php echo $_SESSION['nama_lengkap']; ?></p></div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Alamat Sekarang :</label>
<div class="col-md-3"><p class="form-control-static" ><?php echo $_SESSION['alamat_lengkap']; ?></p></div>
</div>
<div class="form-group">
<label class="col-md-2 control-label">Nomer Telepon :</label>
<div class="col-md-3"><p class="form-control-static" ><?php echo $_SESSION['nope_rt']; ?></p></div>
</div>
</form>
</div>
Tetapi untuk $query3 gagal gan. Ane rencananya nampilin dalam bentuk tabel sesuai dengan no RT nya yang ane samakan dengan username session. Tetapi kagak muncul
Berikut untuk tampilan kegagalannya
Spoiler for Tampilan gagal :
Bisa di lihat gan untuk nomer KTP aja nggak muncul
untuk Nama, Alamat, dst belum ane beri session karena ane nyoba yang nomer KTP dulu. Ane inginnya yang muncul data2 di database yang sesuai dengan RT loginnya
Spoiler for Coding session gagal menampilkan tabel :
dan ini codenya
[SPOILER=Coding gagal]
Code:
<?php
$txt_name = "salternatif";
$btn_name = "balternatif";
if(isset($_POST[$txt_name])){ $src = $_POST[$txt_name];
}else{ $src = $_SESSION[$txt_name]; }
$_SESSION[$txt_name] = $src;
?>
<section id="main-content">
<section class="wrapper">
<div class="row">
<div class="col-lg-12">
<h3 class="page-header"><i class="fa fa-file-text-o"></i>Alternatif</h3>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i><a href="index.html">Home</a></li>
<li><i class="icon_document_alt"></i>Alternatif</li>
</ol>
</div>
</div>
<div class="row">
<div class="col-md-12">
<!-- START panel-->
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Alternatif List</h3>
</div>
<div class="panel-footer">
<div class="row">
<form id="navbar-search" action="" class="navbar-search" method="POST">
<div class="col-lg-4">
<div class="input-group">
<input type="text" placeholder="Search" class="input-sm form-control" name="<?=$txt_name?>" value="<?=$src?>">
<span class="input-group-btn">
<button type="submit" class="btn btn-sm btn-default">Search</button>
</span>
</div>
</div>
</form>
<div class="col-lg-8">
<div class="input-group pull-right">
<div class="btn-group">
</div>
</div>
</div>
</div>
</div>
<!-- START table-responsive-->
<div class="panel-body">
<div class="table-responsive table-bordered">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>No.KTP</th>
<th>Nama</th>
<th>Alamat</th>
<th>Score</th>
<th>Keterangan</th>
</tr>
</thead>
<tbody>
<?php
$qfrom = mysql_query("select * from za_alternatif where Alamat like '%$src%' or Nama like '%$src%' ORDER BY No_Ktp");
$No =0;
while($row=mysql_fetch_array($qfrom)){ $No++;
$jum = mysql_fetch_assoc(mysql_query("select sum(Nilai) as Nilai from za_krialt where No_Ktp='".$row['No_Ktp']."'"));
$jrow = mysql_num_rows(mysql_query("select * from za_krialt where No_Ktp='".$row['No_Ktp']."'"));
?>
<tr>
<td><?=$No?>
<a href="?page=form_alternatif&No_Ktp=<?=$row['No_Ktp']?>">
<div class="label-edit"><em class="fa fa-edit"></em> Edit</div></a>
<a href="?page=cetak_alternatif&No_Ktp=<?=$row['No_Ktp']?>">
<div class="label-edit"><em class="fa fa-print"></em> Print</div></a>
</td>
<td><? echo $_SESSION ['No_Ktp']?></td>
<td><?=$row['Nama']?></td>
<td><?=$row['Alamat']?></td>
<td align="right"><?=round($jum['Nilai']/$jrow,3)?></td>
<td align="right">
<?php
if(round($jum['Nilai']/$jrow,3)<=3.5){ echo "Kurang Mampu"; }else
if(round($jum['Nilai']/$jrow,3)>3.5 && round($jum['Nilai']/$jrow,3)<=7){ echo "Kurang Mampu"; }else
if(round($jum['Nilai']/$jrow,3)>7 && round($jum['Nilai']/$jrow,3)<=10){ echo "Mampu"; }else{
echo "-";
}
?>
</td>
</tr>
<?php } ?>
<?php
if($No<=0){
echo "<tr>
<td colspan='5' align='center'>Not found</td>
</tr>";
}
?>
</tbody>
</table>
</div>
<!-- END panel-->
</div>
Kemudian ini databasenya gan...
Spoiler for Database :
mohon bantuannya
Spoiler for tb_biodatart :
Spoiler for userlog :
Spoiler for za_alternatif :