Menampilkan Data Table berdasarkan session login user

contoh kasus:

saya punya dua table

1. tbl_login: isinya> id_login | id_siswa | username | password | level

2. tbl_siswa: isinya> id_siswa | nama | kelas |

Pertanyaan: bagaimana saya bisa menampilkan data detail siswa setelah login dengan menggunakan session login?

mohon bantuannya para master!!!

avatar tanziltc
@tanziltc

3 Kontribusi 0 Poin

Diperbarui 3 tahun yang lalu

4 Jawaban:

<div>Ya diquery lg gan buat nampilin apa aja yg mau ditampilkan di view. Buat session login yg bsa dijadikan primary key untuk mencari detail siswa.</div>

avatar ngadiono
@ngadiono

27 Kontribusi 14 Poin

Dipost 3 tahun yang lalu

<div>INI BENTUK FORM LOGINNYA:<br><br>&lt;?php<br> $username = @$_POST['username'];<br> $password = @$_POST['password'];<br> $login = @$_POST['login'];<br><br> if ($login) {<br> if ($username == "" || $password == "") {<br> ?&gt;&nbsp;<br> &lt;script type="text/javascript"&gt;<br> alert("Password tidak boleh kosong");<br> &lt;/script&gt;<br> &lt;?php<br> }else{<br> $sql = mysqli_query($koneksi,"Select * from tbl_login where username = '$username' and password = md5('$password') ") or die (mysqli_error());<br> $data = mysqli_fetch_array($sql);<br> $cek = mysqli_num_rows($sql);<br> if ($cek &gt;= 1) {<br> if ($data['level'] == "siswa") {<br> @$_SESSION['siswa'] = $data['id_login'];<br> @$_SESSION['data_siswa'] = $data['id_login'];<br> header("location:siswa.php");<br> }<br> }else{<br> echo "login gagal";<br> }<br> }<br> }<br>?&gt;<br><br>mohon bantuannya, kira-kira seperti apa kode indeknya?<br>@<a href="https://sekolahkoding.com/user/ngadiono">@ngadiono</a>: makasih masukannya.... mohon pencerahannya gan</div>

avatar tanziltc
@tanziltc

3 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

<div>if(isset($_SESSION['id_login']){<br>Ambil isi tabel nya disini<br>}</div>

avatar Chin
@Chin

63 Kontribusi 13 Poin

Dipost 3 tahun yang lalu

<div>Muncul error ini gan:<br><br><strong>Fatal error</strong>: Cannot use isset() on the result of an expression (you can use "null !== expression" instead) in <strong>C:\xampp\htdocs\AuliaCen\pages\siswa.php</strong> on line <strong>5<br><br>ini code viewnya:<br><br>&lt;?php<br>@session_start();<br>include "../koneksi.php";<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(isset(@$_SESSION['id_login'])){ //INI kode baru yang agan saran....<br><br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // query SQL menampilkan data dari table tbl_biodata<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $sql = "SELECT * FROM tbl_siswa WHERE id_siswa='$id_login'";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // tampung data (dalam array) kedalam variable $biodata<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $biodata = mysqli_query($koneksi, $sql);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // variable untuk membuat tabel HTML<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $strTbl = "";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $strTbl .= "&lt;table id='data_siswa' float='left class='table table-bordered table-hover'&gt;";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // cek apakah $biodata nilai kosong atau tidak<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (mysqli_num_rows($biodata) &gt; 0) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // jika ada tampilkan kedalam tabel<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $data = mysqli_fetch_assoc($biodata);&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; ?&gt;<br>&lt;div class="box"&gt;<br>&nbsp; &lt;div class="box-body"&gt;<br>&lt;!-- DataTables Example --&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="card-body"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;div class="table-responsive" float="left"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;table id="data_siswa" class="table table-bordered table-hover"&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;thead&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th colspan="4"&gt;Anda Login Sebagai: &lt;?php echo $data['nama'];?&gt;&lt;/th&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/thead&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tbody&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th&gt;Nama&lt;/th&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;:&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;&lt;?php echo $data['nama'];?&gt;&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;th&gt;Kelas&lt;/th&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;:&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;td&gt;&lt;?php echo $data['kelas'];?&gt;&lt;/td&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/tr&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;?php<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } else {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // jika data tidak ada, tampilkan pesan didalam tabel<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $strTbl .="&lt;tr&gt;&lt;td colspan='2'&gt;Ooouppsss... Maaf, data masih kosong, tambahkan data dari Database terlebih dahulu&lt;/td&gt;&lt;/tr&gt;";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $strTbl .= "&lt;/table&gt;";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // tampilkan tabel pada halaman<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print($strTbl);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;?&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&lt;/tbody&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/table&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &lt;/div&gt;<br>&nbsp; &lt;/div&gt;<br>&lt;/div&gt;<br><br>&lt;?php&nbsp;<br>}else{<br>&nbsp; header("location:login_siswa.php");<br>}<br>?&gt;</strong></div>

avatar tanziltc
@tanziltc

3 Kontribusi 0 Poin

Dipost 3 tahun yang lalu

Login untuk ikut Jawaban