Langsung aja .
- file Database name: bandingkan.sqlCode:
-- phpMyAdmin SQL Dump
-- version 2.7.0-pl2
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Feb 14, 2014 at 06:46 PM
-- Server version: 5.0.18
-- PHP Version: 5.1.2
--
-- Database: `bandingkan`
--
-- --------------------------------------------------------
--
-- Table structure for table `koleksi_produk`
--
CREATE TABLE `koleksi_produk` (
`kd_KProduk` varchar(6) NOT NULL,
`nm_produk` varchar(30) NOT NULL,
`harga` int(15) NOT NULL default '0',
`diskon` int(2) NOT NULL,
`stok` int(4) NOT NULL default '0',
PRIMARY KEY (`kd_KProduk`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `koleksi_produk`
--
INSERT INTO `koleksi_produk` VALUES ('KP0003', 'ASUS ZENBOOK Touch UX31A', 11700000, 0, 3);
INSERT INTO `koleksi_produk` VALUES ('KP0002', 'ASUS A46CA', 4900000, 5, 10);
INSERT INTO `koleksi_produk` VALUES ('KP0001', 'ASUS A45A', 4500000, 0, 10);
INSERT INTO `koleksi_produk` VALUES ('KP0004', 'SAMSUNG ATIV Book 9 Lite Touch', 6900000, 0, 3);
INSERT INTO `koleksi_produk` VALUES ('KP0005', 'Series 3 Ultrabox NP370R4V', 4000000, 0, 5);
INSERT INTO `koleksi_produk` VALUES ('KP0006', 'SAMSUNG Series 5 Ultrabook NP5', 7000000, 0, 5);
INSERT INTO `koleksi_produk` VALUES ('KP0007', 'EPSON WF-3521', 2700000, 15, 5);
INSERT INTO `koleksi_produk` VALUES ('KP0008', 'EPSON WF-7011', 7200000, 5, 5);
INSERT INTO `koleksi_produk` VALUES ('KP0009', 'HP A9U23B', 3000000, 10, 5);
INSERT INTO `koleksi_produk` VALUES ('KP0010', 'HP B2L56D', 650000, 0, 10); - file koneksi.phpPHP Code:
$host="localhost";$id="root";$pass="password";$db="bandingkan";mysql_connect($host, $id, $pass) or die ("akses tidak terhubung". mysql_error());mysql_select_db($db) or die ("akses database tidak terhubung". mysql_error());
- file index.phpPHP Code:
<?php
session_start();
include "koneksi.php";?><html>
<head>
<title>Daftar Kategori</title>
</head>
<body>
<!-- Products -->
<?php
$sqlc = "SELECT *
FROM koleksi_produk
ORDER BY koleksi_produk.kd_KProduk DESC";
$qryc=mysql_query($sqlc) or die ("Gagal Query<br>".mysql_error());
while ($datac = mysql_fetch_array($qryc)){
$harga = $datac['harga'] - (($datac['harga']*$datac['diskon'])/100);
?> <p><?php echo $datac['nm_produk']."<br>".$datac['harga']; ?></p>
<?php echo "<font size='2'><i>Diskon</i> : </font> ".$datac['diskon']." %";?><br>
<?php echo "<font size='2'><i>Stok</i> : </font> ".$datac['stok']."<br>Harga : ".$harga;?>
<a href='bandingkan.php?aksi=add&kode=<?php echo $datac['kd_KProduk'];?>'>bandingkan</a>
<hr>
<?php } ?></body>
</html> - file bandingkan.phpPHP Code:
<?php
session_start();
include "koneksi.php";$TxtSesIDProd = $_SESSION['kode'];$aksi = $_GET['aksi'];
switch ($aksi) {
case 'add':
if ($TxtSesIDProd) {
$TxtSesIDProd .= ','.$_GET['kode'];
} else {
$TxtSesIDProd = $_GET['kode'];
}
break;
case 'hapus':
if ($TxtSesIDProd) {
$ikode = explode(',',$TxtSesIDProd);
$bkode = '';
foreach ($ikode as $nilai) {
if ($_GET['kode'] != $nilai) {
if ($bkode != '') {
$bkode .= ','.$nilai;
} else {
$bkode = $nilai;
}
}
}
$TxtSesIDProd = $bkode;
}
break;
}
$_SESSION['kode'] = $TxtSesIDProd; $ikode = explode(',',$TxtSesIDProd);
if ($TxtSesIDProd) {
$ikode = explode(',',$TxtSesIDProd);
$contents = array();
foreach ($ikode as $nilai) {
$contents[$nilai] = (isset($contents[$nilai])) ? $contents[$nilai] + 1 : 1;
}
echo " <table border='0'>";
echo "<tr>";
echo "<td width='209'><b> Nama Barang</b></td>";
echo "<td width='140'><b>Harga Lama</b></td>";
echo "<td width='140'><b>Harga Baru</b></td>";
echo "<td width='50'><b>Hapus</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='6'> </td>";
echo "</tr>";
echo "</table>";
echo "<table border='0'>";
foreach ($contents as $id=>$qty) {
$sql = "SELECT * FROM koleksi_produk
WHERE kd_KProduk = '$id'";
$result = mysql_query($sql) or die ("Gagal menampilkan nama Produk<br>".mysql_error());
$data = mysql_fetch_array($result);
$harga = $data['harga'] - (($data['harga']* $data['diskon'])/100);
echo "<tr>";
echo "<td bgcolor='#F0F0F0' width='220'><a href='index.php?page=proddet&kode=$data[kd_KProduk]'>$data[nm_produk]</a></td>";
echo "<td bgcolor='#F0F0F0' width='140'><p align='right'><s>Rp.".$data['harga'].",00</s></p></td>";
echo "<td bgcolor='#F0F0F0' width='140'><p align='right'>Rp.".$harga.",00</i></p>";
echo "<td width='50' bgcolor='#909090'>";
echo "<a href='?aksi=hapus&kode=".$data['kd_KProduk']."'>Remove</a>";
echo "</td>";
echo "</tr>";
}
echo "</table> ";
}
else {
echo '<p>Daftar Barang Anda Kosong</p>';
}
?>
Silahkan diapain aja bang, ane ridho.. deh.
Oh iya bang caranya ngasih rate gimana yah, masa ane udah cari2 petunjuknya disini belum ketemu-ketemu sih..
Mohon petunjuknya..
0 komentar:
Post a Comment