KOMUNITAS
Home / FORUM / All / Tech / ... / Programmer Forum /
Menampilkan data barang berdasarkan id yang login
KASKUS
51
244
https://www.kaskus.co.id/thread/5783d3e3a2c06e59338b4567/menampilkan-data-barang-berdasarkan-id-yang-login

Menampilkan data barang berdasarkan id yang login

gan mau tanya cara menampilkan data barang berdasarkan id yang login gimana ya ?

login.php
Code:
<?php
if(isset($_POST['login'])){
include("koneksi.php");

$username = $_POST['username'];
$password = md5($_POST['password']);
$level = $_POST['level'];

if ($level == 'admin') {
$sql1 = mysqli_query($koneksi, "SELECT * FROM admin WHERE username='$username' AND password='$password'");
$data1 = mysqli_fetch_array($sql1);
$id = $data1[0];
$cek1=mysqli_num_rows($sql1);
if ($cek1 > 0) {
$_SESSION['admin'] = $id;
header('Location: admin.php');
}
else
{
echo '<div class="alert alert-info text-center" id=divAlert >Username atau Password salah </div>';
}
} else if ($level == 'toko') {
$sql2 = mysqli_query($koneksi, "SELECT * FROM toko WHERE username='$username' AND password='$password'");
$data2 = mysqli_fetch_array($sql2);
$id = $data1[0];
$cek2=mysqli_num_rows($sql2);
if ($cek2 > 0) {
$_SESSION['toko'] = $id;
header('Location: toko.php');
}
else
{
echo '<div class="alert alert-info text-center" id=divAlert >Username atau Password salah </div>';
}

}
}
?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">

<!--[if lt IE 9]>
[removed][removed]
[removed][removed]
<![endif]-->

</head>

<body>

<div class="row">
<div class="col-xs-10 col-xs-offset-1 col-sm-8 col-sm-offset-2 col-md-4 col-md-offset-4">
<div class="login-panel panel panel-default">
<div class="panel-heading">Log in</div>
<div class="panel-body">
<form role="form" method="post">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" name="username" type="text" required autofocus=""></input>
</div>

<div class="form-group">
<input class="form-control" placeholder="Password" name="password" type="password" required value=""></input>
</div>

<div class="form-group">
<select name="level" class="form-control">
<option value="admin">Admin</option>
<option value="toko">Toko</option>
</select>
</div>
<button type="submit" class="btn btn-primary" name="login">Login</button>
</fieldset>
</form>
</div>
</div>
</div><!-- /.col-->
</div><!-- /.row -->

<div class="container">
<hr>
<center><p class="centered">Created by Fery Setiawan - 2016</p></center>
</div><!-- /container -->


[removed][removed]
[removed][removed]
[removed]

$(function(){
setTimeout(function(){$("#divAlert").fadeOut(1500)}, 1000);
});
!function ($) {
$(document).on("click","ul.nav li.parent > a > span.icon", function(){
$(this).find('em:first').toggleClass("glyphicon-minus");
});
$(".sidebar span.icon").find('em:first').addClass("glyphicon-plus");
}(window.jQuery);

$(window).on('resize', function () {
if ($(window).width() > 768) $('#sidebar-collapse').collapse('show')
})
$(window).on('resize', function () {
if ($(window).width() <= 767) $('#sidebar-collapse').collapse('hide')
})
[removed]
</body>

</html>


toko.php
Code:
<?php
session_start();
if(empty($_SESSION)){
header("Location: login.php");
}
?>

<?php
require 'koneksi.php';

?>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Menu Toko</title>

<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-table.css" rel="stylesheet">
<link href="css/styles.css" rel="stylesheet">

<!--Icons-->
[removed][removed]

<!--[if lt IE 9]>
[removed][removed]
[removed][removed]
<![endif]-->

</head>

<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#sidebar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="admin.php"><span>Menu </span>Toko</a>
<ul class="user-menu">
<li><a href="logout.php"><svg class="glyph stroked male-user"><use xlink:href="#stroked-male-user"></use></svg> Log out </a>
</li>
</ul>
</div>

</div><!-- /.container-fluid -->
</nav>

<div id="sidebar-collapse" class="col-sm-3 col-lg-2 sidebar">
<ul class="nav menu">
<li><a href="tambahbarang.php"><svg class="glyph stroked pencil"><use xlink:href="#stroked-pencil"></use></svg> Tambah Barang</a></li>
<li><a href="listdokter.php"><svg class="glyph stroked calendar"><use xlink:href="#stroked-table"></use></svg> List Dokter</a></li>
</ul>

</div><!--/.sidebar-->

<div class="col-sm-9 col-sm-offset-3 col-lg-10 col-lg-offset-2 main">

<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">List Barang</div>
<div class="panel-body">
<table data-toggle="table" data-show-refresh="true" data-show-toggle="true" data-show-columns="true" data-search="true" data-select-item-name="toolbar1" data-pagination="true" data-sort-name="name" data-sort-order="desc">
<thead>
<tr>
<th>No</th>
<th>Nama Barang</th>
<th>Merk Barang</th>
<th>Jumlah Barang</th>
<th>Harga Barang</th>
<th>Keterangan Barang</th>
<th>Update / Delete</th>
</tr>
</thead>
<tbody>
<?php
include 'koneksi.php';
$username=$_GET['username'];
$query = "select * from barang where id_barang=username";
$res = mysqli_query($koneksi,$query);
while($row=mysqli_fetch_array($res)){
echo '<tr>';
echo '<td>'. $row['id_barang'] . '</td>';
echo '<td>'. $row['nama_barang'] . '</td>';
echo '<td>'. $row['merk_barang'] . '</td>';
echo '<td>'. $row['jumlah_barang'] . '</td>';
echo '<td>'. $row['harga_barang'] . '</td>';
echo '<td>'. $row['keterangan_barang'] . '</td>';
echo '<td>
<a class="btn btn-xs btn-primary" href="updatedokter.php?id_dokter='. $row['id_dokter'] . '">Update</a>
<a class="btn btn-xs btn-danger" href="deletedokter.php?id_dokter='. $row['id_dokter'] . '">Delete</a>
</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div><!--/.row-->
</div><!--/.main-->

[removed][removed]
[removed][removed]
[removed][removed]
[removed]
$(function () {
$('#hover, #striped, #condensed').click(function () {
var classes = 'table';

if ($('#hover').prop('checked')) {
classes += ' table-hover';
}
if ($('#condensed').prop('checked')) {
classes += ' table-condensed';
}
$('#table-style').bootstrapTable('destroy')
.bootstrapTable({
classes: classes,
striped: $('#striped').prop('checked')
});
});
});

function rowStyle(row, index) {
var classes = ['active', 'success', 'info', 'warning', 'danger'];

if (index % 2 === 0 && index / 2 < classes.length) {
return {
classes: classes[index / 2]
};
}
return {};
}
[removed]
</body>

</html>
Diubah oleh ferywell
maksudnya gimana gan?
konteksnya ga jelas.

coba kasih struktur tabelnya, contoh datanya, dan contoh output yg diinginkan.
Spoiler for contoh tabel barang:


Spoiler for contoh tabel toko:


Spoiler for contoh output menggunakan user starbaby:


Spoiler for contoh output menggunakan user candy:


kurang lebih seperti itu gan
Diubah oleh ferywell
Quote:


Spoiler for contoh tabel barang:


Spoiler for contoh tabel toko:


Spoiler for contoh output menggunakan user starbaby:


Spoiler for contoh output menggunakan user candy:


kurang lebih seperti itu gan

Quote:



query table toko pake where id_toko = $__SESSION['toko']
Diubah oleh darkwinx
Quote:


maksud agan apakah begini ?

Menampilkan data barang berdasarkan id yang login

tapi ini belum muncul juga barang nya gan
Quote:



$_SESSION['toko'] nya coba ga usah pake petik.
cek juga variable yg lain isinya udah bener belum
Quote:


iya gan ini juga ngecek ngecek, puyeng dari kemaren belum bisa bisa


×
© 2022 KASKUS, PT Darta Media Indonesia. All rights reserved
Ikuti KASKUS di