/home/nondinda/domains/nondindaengcity.go.th/public_html/php_webboard_v1/category.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
session_start
();
require(
'check_admin.php');
require(
'bin/connectdb.php');
if(!empty(
$_POST['btOrderSave'])){//กดปุ่มบันทึการจัดเรียง
 
foreach($_POST['cg_order'] as $cg_id => $cg_order){
  
//Update การจัดเรียงลำดับของหมวดกระทู้
    
mysql_query("UPDATE tbl_category SET cg_order='$cg_order' WHERE cg_id='$cg_id'");
 } 
}
if(!empty(
$_GET['del'])){//กดลบหมวดกระทู้
 
mysql_query('DELETE FROM tbl_category  WHERE cg_id='.$_GET['del']);
 
header('category.php');
}
//แสดงหมวดหมุ่กระทู้ทั้งหมดโดยเรียงตามลำดับ cg_order จากน้อยไปมาก
$rs_category=mysql_query("SELECT cg_id,cg_name FROM tbl_category ORDER BY cg_order ASC"); 
$chk_rows_category=mysql_num_rows($rs_category);//นับจำนวนแถวของหมวดกระทู้
?>
<html>
    <head>
        <?php require('head.php'); ?>
        <title>จัดการหมวดกระทู้</title>
    </head>
    <body>
        <?php require('menu.php'); ?>
        <div class="container">
            <?php require('header.php'); ?>
            <div class="row ws-content">
             <div class="col-md-10 col-sm-10 col-md-offset-1 col-sm-offset-1">
               <form id="categoryForm" name="categoryForm" method="post" action="" >
                 <table class="table table-bordered table-hover">
                   <thead>
                     <tr>
                       <th colspan="4">
                       <div style="float:right">
                       <span class="btn btn-default" ><a href="category_add.php">เพิ่มหมวดกระทู้</a></span>
                       <input type="submit" name="btOrderSave" id="btOrderSave" class="btn btn-primary" value="บันทึกการจัดเรียง" >
                       </div>
                       </th>
                     </tr>
                     <tr>
                       <th style="text-align:center">ลำดับ</th>
                       <th>ชื่อหมวดกระทู้</th>
                       <th>เรียงลำดับ</th>
                       <th>จัดการ</th>
                     </tr>
                   </thead>
                   <tbody>
                   <?php if($chk_rows_category>0) {//จำนวนแถวมากกว่า 0 แสดงว่ามีข้อมูล
        
$order_i=1;
        while(
$show_category=mysql_fetch_assoc($rs_category)){
         
$cg_id=$show_category['cg_id'];
        
?>
                     <tr>
                       <td style="width:10%;text-align:center"><?php echo  $order_i;?></td>
                       <td style="width:70%"><?php echo $show_category['cg_name'];?></td>
                       <td style="width:10%"><input type="text" name="cg_order[<?php echo  $cg_id;?>]"  class="form-control cg_order" value="<?php echo  $order_i;?>" ></td>
                       <td style="width:10%">
                       <a href="category_edit.php?edit=<?php echo  $cg_id;?>">แก้ไข</a> /
                       <a href="category.php?del=<?php echo  $cg_id;?>" onClick="return confirm('ยืนยันการลบหมวดกระทู้นี้')">ลบ</a></td>
                     </tr>
                     <?php 
      $order_i
++;
        }
      }else{ 
//ไม่มีข้อมูลหมวดกระทู้
      
?>
                     <tr>
                       <td colspan="4" align="center">ไม่พบข้อมูล</td>
                     </tr>
                     <?php ?>
                   </tbody>
                 </table>
               </form>
             </div>
            </div>
            <?php require('footer.php'); ?>
        </div>      
    </body>
</html>
</body>
</html>