Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DATABASE examples
- ==============
- /*
- #table creation
- USE `test`;
- DROP TABLE IF EXISTS `tbl_order`;
- CREATE TABLE IF NOT EXISTS `tbl_order` (
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'primary key untuk table tbl_order',
- `id_order` varchar(30) NOT NULL COMMENT 'ID Order',
- `status` tinyint(2) unsigned NOT NULL DEFAULT 0,
- PRIMARY KEY(`id`)
- ) ENGINE=MyISAM COMMENT='tabel untuk menyimpan data order';
- INSERT INTO `tbl_order`(`id`,`id_order`,`status`) VALUES
- (NULL,'PO00007',1),
- (NULL,'PO00006',1),
- (NULL,'PO00005',0),
- (NULL,'PO00004',1),
- (NULL,'PO00003',2),
- (NULL,'PO00002',1),
- (NULL,'PO00001',3);
- */
- FILE : db.php
- ==============
- <?php
- //database configuration
- $dbhost='localhost';
- $dbuser='root';
- $dbpass='';
- $dbname='test';
- //database connection
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- ?>
- FILE : order.php
- ==============
- <?php
- include 'db.php';
- $sql="SELECT * FROM tbl_order";
- $result=$db->query($sql);
- function selection($id,$value=0){
- $options=array('Pending','Confirmed','Cancelled','Shipped');
- echo "<select id='$id'>\n";
- for($i=0;$i<4;$i++){
- echo "<option".($value==$i?' selected="selected"':'')." value='$i'>".$options[$i]."</option>\n";
- }
- echo "/<select>\n";
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Edit </title>
- <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
- <style type="text/css">
- th {font-family:arial,sans-serif;font-size:12px;background-color:#bbf;}
- td {font-family:arial,sans-serif;font-size:12px;}
- </style>
- </head>
- <body>
- <table>
- <thead>
- <tr>
- <th>No</th>
- <th>ID Order</th>
- <th>Status</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $i=0;
- while($records=$result->fetch_object()){
- echo "
- <tr>
- <td>".++$i."</td>
- <td>".$records->id_order."</td>
- <td>";
- selection('s'.$records->id,$records->status);
- echo "
- </td>
- </tr>\n";
- }
- ?>
- </tbody>
- </table>
- <script>
- $(document).ready(function(){
- $('select').change(function(){
- $.post("order.process.php", { status: $(this).val(), id: $(this).attr('id').substring(1) } );
- });
- });
- </script>
- </body>
- </html>
- FILE : order.process.php
- ==============
- <?php
- include 'db.php';
- if(isset($_POST['status']) && isset($_POST['id'])){
- $db=new mysqli($dbhost,$dbuser,$dbpass,$dbname);
- $sql="UPDATE tbl_order "
- ."SET status='".$_POST['status']."' "
- ."WHERE id='".$_POST['id']."'";
- $db->query($sql);
- $db->close();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement