Advertisement
GWibisono

script booking bus

Oct 12th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.94 KB | None | 0 0
  1. <?php
  2. $mysqli = new mysqli("localhost", "root", "", "work_fb02");
  3.  
  4.     /* check connection */
  5.     if (mysqli_connect_errno()) {
  6.         printf("Connect failed: %s\n", mysqli_connect_error());
  7.         exit();
  8.     }
  9.  
  10. @isset($_GET['act'])?$act=$_GET['act']:"";
  11. if(isset($act)&&$act=='tiket')
  12. {
  13.     $res=array();
  14.     $id=$_GET['id'];
  15.     $sql="select count(*) c from bus_tiket where bus=$id and status=1";
  16.     $q=$mysqli->query($sql);
  17.     if(!$q)
  18.         {
  19.             die($mysqli->error.$sql);
  20.         }
  21.        
  22.     $r=$q->fetch_assoc();
  23.     $res['total']=$r['c'];
  24.     $sql="select * from bus_tiket where bus=$id and status=1";
  25.     $q=$mysqli->query($sql);
  26.     $a=array();
  27.     if(!$q)
  28.         {
  29.             die($mysqli->error);
  30.         }
  31.     while($r = $q->fetch_assoc())
  32.     {
  33.         $r['link']="<a      >Lihat</a>";
  34.         $r['tanggal']=date("d-m-Y",strtotime($r['tanggal']));
  35.        
  36.         $a[]=$r;
  37.     }
  38.     $res['rows']=$a;
  39.     $json=json_encode($res);
  40. die($json);
  41. }
  42. //===================
  43. if(isset($act)&&$act=='bus')
  44. {
  45.     $res=array();
  46.     $sql="select count(*) c from bus";
  47.     $q=$mysqli->query($sql);
  48.     if(!$q)
  49.         {
  50.             die($mysqli->error.$sql);
  51.         }
  52.        
  53.     $r=$q->fetch_assoc();
  54.     $res['total']=$r['c'];
  55.     $sql="select *   from bus ";
  56.     $q=$mysqli->query($sql);
  57.     $a=array();
  58.     if(!$q)
  59.         {
  60.             die($mysqli->error);
  61.         }
  62.     while($r = $q->fetch_assoc())
  63.     {
  64.         $r['link']="<a href='?bus=$r[id]'>Lihat</a>";
  65.         $a[]=$r;
  66.     }
  67.     $res['rows']=$a;
  68.     $json=json_encode($res);
  69. die($json);
  70. }  
  71. ?>
  72. <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/css/main.css">
  73.     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/metro-green/easyui.css">
  74.     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/themes/icon.css">
  75.     <link rel="stylesheet" type="text/css" href="http://www.jeasyui.com/easyui/demo/demo.css">
  76.     <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery-1.8.0.min.js"></script>
  77.     <script type="text/javascript" src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
  78. <?php
  79. if(isset($_GET['bus']))
  80. {
  81. ?><div style='text-align:left;padding:10px 15px'><a href="?1">back</a></div>
  82.  <table class="easyui-datagrid" title="BUS" style="width:700px;height:250px"
  83.  data-options="singleSelect:true,collapsible:true,
  84.  url:'?act=tiket&id=<?=$_GET['bus'];?>',method:'get'">
  85.         <thead>
  86.             <tr>
  87.                 <th data-options="field:'tanggal',width:150">Tanggal Berangkat</th>            
  88.                 <th data-options="field:'nama',width:90,align:'center'">Nama</th>
  89.             </tr>
  90.         </thead>
  91.     </table>
  92. <?
  93. }else{
  94. ?>
  95.  <table class="easyui-datagrid" title="BUS" style="width:700px;height:250px"
  96.             data-options="singleSelect:true,collapsible:true,url:'?act=bus',method:'get'">
  97.         <thead>
  98.             <tr>
  99.                 <th data-options="field:'bus',width:80">BUS</th>            
  100.                 <th data-options="field:'link',width:60,align:'center'">&nbsp;</th>
  101.             </tr>
  102.         </thead>
  103.     </table>
  104. <?
  105. }
  106. /*
  107. CREATE TABLE IF NOT EXISTS `bus` (
  108.   `id` int(11) NOT NULL AUTO_INCREMENT,
  109.   `bus` varchar(50) NOT NULL,
  110.   PRIMARY KEY (`id`)
  111. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
  112.  
  113.  
  114.  
  115. INSERT INTO `bus` (`id`, `bus`) VALUES
  116. (1, 'bus1'),
  117. (2, 'bus2');
  118.  
  119.  
  120.  
  121. CREATE TABLE IF NOT EXISTS `bus_tiket` (
  122.   `id` int(11) NOT NULL AUTO_INCREMENT,
  123.   `bus` int(11) NOT NULL,
  124.   `tanggal` date NOT NULL,
  125.   `nama` varchar(50) NOT NULL,
  126.   `input` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  127.   `status` int(11) NOT NULL DEFAULT '1',
  128.   PRIMARY KEY (`id`)
  129. ) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;
  130.  
  131.  
  132.  
  133. INSERT INTO `bus_tiket` (`id`, `bus`, `tanggal`, `nama`, `input`, `status`) VALUES
  134. (1, 1, '2013-10-12', 'Nama1', '2013-10-12 15:13:13', 0),
  135. (2, 1, '2013-10-12', 'Nama2', '2013-10-12 15:13:13', 1),
  136. (3, 1, '2013-10-12', 'Nama3', '2013-10-12 15:13:13', 1),
  137. (4, 1, '2013-10-14', 'Nama4', '2013-10-12 15:13:13', 1),
  138. (5, 1, '2013-10-12', 'Nama5', '2013-10-12 15:13:13', 1);
  139.  
  140. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement