Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /********************************
- / SEARCH BARANG BY KATEGORI
- / FILENAME : barang.php
- / UPDATED BY : CAHYA DSN
- / CREATED DATE : 2013-07-24
- /*******************************
- -- Database: `test`
- --
- -- Table structure for table `tbl_kategori`
- --
- DROP TABLE IF EXISTS `tbl_kategori`;
- CREATE TABLE IF NOT EXISTS `tbl_kategori` (
- `id_kategori` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
- `kode_kategori` VARCHAR(10)NOT NULL,
- `nama_kategori` VARCHAR(50) NOT NULL,
- PRIMARY KEY (`id_kategori`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- -- Dumping data for table `tbl_kategori`
- INSERT INTO `tbl_kategori`(`kode_kategori`,`nama_kategori`)
- VALUES
- ('ELK0010001','Televisi'),
- ('ELK0010002','Kulkas'),
- ('ELK0010003','Air Conditioner');
- -- Table structure for table `tbl_barang`
- --
- DROP TABLE IF EXISTS `tbl_barang`;
- CREATE TABLE IF NOT EXISTS `tbl_barang` (
- `id_barang` int(11) unsigned NOT NULL AUTO_INCREMENT,
- `id_kategori` smallint(6) unsigned NOT NULL,
- `kode_barang` VARCHAR(10)NOT NULL,
- `nama_barang` VARCHAR(25) NOT NULL,
- `deskripsi` VARCHAR(255) NOT NULL,
- `stok` int(11) unsigned NOT NULL DEFAULT '0',
- `harga` float NOT NULL DEFAULT '0.0',
- PRIMARY KEY (`id_barang`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
- -- Dumping data for table `tbl_barang`
- INSERT INTO `tbl_barang`(`id_kategori`,`kode_barang`,`nama_barang`,`deskripsi`,`stok`,`harga`)
- VALUES
- ('1','TV21','Televisi 21 inchi','TV LCD 21 inchi',15,1900000),
- ('1','TV24','Televisi 24 inchi','TV LCD 24 inchi',7,2200000),
- ('1','TV29','Televisi 29 inchi','TV LCD 29 inchi',9,2600000),
- ('1','TV32','Televisi 32 inchi','TV LCD 32 inchi',10,3300000),
- ('1','TV40','Televisi 40 inchi','TV LCD 40 inchi',2,5300000),
- ('2','KK100P1','Kulkas 1 pintu 100L','Kulkas 1 pintu 100L',5,1200000),
- ('2','KK140P1','Kulkas 1 pintu 140L','Kulkas 1 pintu 140L',6,1500000),
- ('2','KK220P2','Kulkas 2 pintu 220L','Kulkas 2 pintu 220L',3,3200000),
- ('2','KK240P2','Kulkas 2 pintu 240L','Kulkas 2 pintu 240L',4,3700000),
- ('2','KK250P2','Kulkas 2 pintu 250L','Kulkas 2 pintu 250L',2,4000000),
- ('3','AC12','Air Conditioner 1/2 PK','Air Conditioner 1/2 PK',4,3200000),
- ('3','AC34','Air Conditioner 3/4 PK','Air Conditioner 3/4 PK',3,4200000),
- ('3','AC01','Air Conditioner 1 PK','Air Conditioner 1 PK',4,5200000),
- ('3','AC02','Air Conditioner 2 PK','Air Conditioner 2 PK',2,6100000);
- */
- // Database Configuration
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- // Database Connection
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Search Barang</title>
- </head>
- <body>
- <form method="POST">
- KODE KATEGORI
- <select name="id_kategori">
- <option>-- pilih salah satu</option>
- <?php
- $sql="SELECT * FROM tbl_kategori";
- $result=$db->query($sql);
- while($row=$result->fetch_object())
- {
- echo "<option value='{$row->id_kategori}'>{$row->kode_kategori} - {$row->nama_kategori}</option>\n";
- }
- $result->close();
- ?>
- </select>
- <input type="submit" name="submit" value="search" />
- </form>
- <fieldset>
- <legend>Hasil Pencarian</legend>
- <div id="search_container">
- <?php
- if(isset($_POST['submit']))
- {
- $sql="SELECT k.kode_kategori,k.nama_kategori,b.nama_barang,b.deskripsi,b.stok,b.harga "
- ."FROM tbl_barang b "
- ."JOIN tbl_kategori k USING(id_kategori) "
- ."WHERE k.id_kategori='".(isset($_POST['id_kategori'])?$_POST['id_kategori']:'')."'";
- $result=$db->query($sql);
- if($result->num_rows>0)
- {
- echo "<table>\n"
- ."<tr>\n"
- ."<th>No</th>\n"
- ."<th>Kd Kat</th>\n"
- ."<th>Kategori</th>\n"
- ."<th>Nama</th>\n"
- ."<th>Deskripsi</th>\n"
- ."<th>Stok</th>\n"
- ."<th>Harga</th>\n"
- ."</tr>";
- $i=0;
- while($row=$result->fetch_object())
- {
- echo "<tr>\n"
- ."<td>".++$i."</td>\n"
- ."<td>{$row->kode_kategori}</td>\n"
- ."<td>{$row->nama_kategori}</td>\n"
- ."<td>{$row->nama_barang}</td>\n"
- ."<td>{$row->deskripsi}</td>\n"
- ."<td align='right'>{$row->stok}</td>\n"
- ."<td align='right'>".number_format($row->harga)."</td>\n"
- ."</tr>\n";
- }
- echo "</table>\n";
- $result->close();
- }
- else
- {
- echo "No data found";
- }
- }
- $db->close();
- ?>
- </div>
- </fieldset>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement