2016-03-06 46 views
0

我有一張表,我列出了所有產品並在表格中通過我過濾產品,現在我面臨的問題是我已經提取了SQL中的所有數據,並且我想知道在過濾參數時如何形成新表格。如何通過Post方法在php中的表中獲取值並獲取表中的替換前表

<div class="row"> 
    <div class="col-md-12"> 
    <!-- Begin: life time stats --> 
       <div class="portlet light"> 
        <div class="portlet-title"> 
         <div class="caption"> 
          <i class="fa fa-gift"></i>Products 
         </div> 
         <div class="actions"> 
          <div class="btn-group"> 
           <a class="btn default yellow-stripe dropdown-toggle" href="javascript:;" data-toggle="dropdown"> 
           <i class="fa fa-share"></i> Tools <i class="fa fa-angle-down"></i> 
           </a> 
           <ul class="dropdown-menu pull-right"> 
            <li> 
             <a href="javascript:;"> 
             Export to Excel </a> 
            </li> 
            <li> 
             <a href="javascript:;"> 
             Export to CSV </a> 
            </li> 
            <li> 
             <a href="javascript:;"> 
             Export to XML </a> 
            </li> 
            <li class="divider"> 
            </li> 
            <li> 
             <a href="javascript:;"> 
             Print Invoices </a> 
            </li> 
           </ul> 
          </div> 
         </div> 
        </div> 
        <div class="portlet-body"> 
         <div class="table-container"> 
          <div class="table-actions-wrapper"> 
           <span> 
           </span> 
           <select class="table-group-action-input form-control input-inline input-small input-sm"> 
            <option value="">Select...</option> 
            <option value="publish">Publish</option> 
            <option value="unpublished">Un-publish</option> 
            <option value="delete">Delete</option> 
           </select> 
           <button class="btn btn-sm yellow table-group-action-submit"><i class="fa fa-check"></i> Submit</button> 
          </div> 
          <table class="table table-striped table-bordered table-hover" id="datatable_products"> 
          <thead> 
          <tr role="row" class="heading"> 
           <th width="1%"> 
            <input type="checkbox" class="group-checkable"> 
           </th> 
           <th width="10%"> 
            Product ID 
           </th> 
           <th width="15%"> 
            Product&nbsp;Name 
           </th> 
           <th width="15%"> 
            Category 
           </th> 
           <th width="10%"> 
            Price 
           </th> 
           <th width="10%"> 
            Stock 
           </th> 
           <th width="15%"> 
            SKU 
           </th> 
           <th width="10%"> 
            Status 
           </th> 
           <th width="10%"> 
            Product Image 
           </th> 
          </tr> 
          <tr role="row" class="filter"> 
           <form method="post" action="productlist.php" id="searchform"> 
             <td> 
             </td> 
             <td> 
              <input type="text" class="form-control form-filter input-sm" id="product_id" name="product_id"> 
             </td> 
             <td> 
              <input type="text" class="form-control form-filter input-sm" name="product_name"> 
             </td> 
             <td> 
              <select name="product_category" class="form-control form-filter input-sm"> 
               <option value="">Select...</option> 
               <option value="1">Mens</option> 
               <option value="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Footwear</option> 
               <option value="3">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Clothing</option> 
               <option value="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Accessories</option> 
               <option value="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Fashion Outlet</option> 
               <option value="6">Football Shirts</option> 
               <option value="7">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Premier League</option> 
               <option value="8">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Football League</option> 
               <option value="9">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Serie A</option> 
               <option value="10">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Bundesliga</option> 
               <option value="11">Brands</option> 
               <option value="12">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Adidas</option> 
               <option value="13">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nike</option> 
               <option value="14">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Airwalk</option> 
               <option value="15">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;USA Pro</option> 
               <option value="16">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Kangol</option> 
              </select> 
             </td> 
             <td> 
              <div class="margin-bottom-5"> 
              <input type="text" class="form-control form-filter input-sm" name="product_price_from" placeholder="From"/> 
             </div> 
             </td> 
             <td> 
              <div class="margin-bottom-5"> 
              <input type="text" class="form-control form-filter input-sm" name="product_quantity_from" placeholder="From"/> 
              </div> 
             </td> 
             <td> 
              <div class="input-group date date-picker margin-bottom-5" data-date-format="dd/mm/yyyy"> 
              <input type="text" class="form-control form-filter input-sm" readonly name="product_created_from" placeholder="From"> 
              <span class="input-group-btn"> 
              <button class="btn btn-sm default" type="button"><i class="fa fa-calendar"></i></button> 
              </span> 
              </div> 
             </td> 
             <td> 
              <select name="product_status" class="form-control form-filter input-sm"> 
              <option value="">Select...</option> 
              <option value="published">Complete</option> 
              <option value="published">Cancelled</option> 
              <option value="published">Denied</option> 
              <option value="published">Failed</option> 
              <option value="notpublished">Refund</option> 
              <option value="notpublished">Shipped</option> 
              <option value="notpublished">Delivered</option> 
              <option value="deleted">Reversed</option> 
              </select> 
             </td> 
             <td> 
              <div class="form-actions"> 
               <div class="margin-bottom-5"> 
                <input type="hidden" name="validate"> 
                <button class="btn btn-sm yellow filter-submit margin-bottom" name="search" type="submit"><i class="fa fa-search"></i>Search</button> 
               </div> 
               <button class="btn btn-sm red filter-cancel" type ="reset"><i class="fa fa-times"></i> Reset</button> 
              </div> 
             </td> 
           </form> 
          </tr> 
          </thead> 
          <tbody> 
           <?php 
           global $conn; 
           $result = mysqli_query($conn,"SELECT * FROM nits_product"); 

            while ($record = mysqli_fetch_array($result)) { 
             echo '<tr role="row">'; 
              echo '<td width="1%"><input type="checkbox" class="group-checkable"></td>'; 
              echo'<td data-th="Product ID">' . $record['product_id'] . '</td>'; 
              echo'<td data-th="Product&nbsp;Name">' . $record['product_name'] . '</td>'; 
              echo'<td data-th="Category">' . $record['product_categories'] . '</td>'; 
              echo'<td data-th="Price">' . $record['product_price'] . '</td>'; 
              echo'<td data-th="Stock">' . $record['product_stock'] . '</td>'; 
              echo'<td data-th="SKU">' . $record['product_sku'] . '</td>'; 
              echo'<td data-th="Status">' . $record['product_status'] . '</td>'; 
              echo'<td data-th="Product Image">' . $record['product_images'] . '</td>'; 

             echo '</tr>'; 
           }?> 
          </tbody> 
          </table> 
         </div> 
        </div> 
       </div> 
       <!-- End: life time stats --> 
      </div> 
     </div> 

在此先感謝!

+0

你想刷新頁面? –

+0

不需要。我想根據搜索查詢將表與新數據項綁定。 –

回答

0

var Content = function() { 
 

 
    var initPickers = function() { 
 
     //init date pickers 
 
     $('.date-picker').datepicker({ 
 
      rtl: Metronic.isRTL(), 
 
      autoclose: true 
 
     }); 
 
\t \t 
 
\t \t 
 
    } 
 

 
     
 
    var handleData = function() { 
 
     var grid = new Datatable(); 
 

 
     grid.init({ 
 
      src: $("#datatable_content"), 
 
      onSuccess: function (grid) { 
 
       // execute some code after table records loaded 
 
      }, 
 
      onError: function (grid) { 
 
       // execute some code on network or other general error 
 
      }, 
 
      loadingMessage: 'Loading...', 
 
      dataTable: { 
 
\t \t \t \t "lengthMenu": [ 
 
        [5, 10, 20, 50, 100, 150], 
 
        [5, 10, 20, 50, 100, 150] // change per page values here 
 
       ], 
 
\t \t \t \t 
 
\t \t \t \t 
 
       "pageLength": 5, // default record count per page 
 
       "ajax": { 
 
        "url": "?route=ajaxTableContent"//dataTable, // ajax source 
 
       }, 
 
       "order": [ 
 
        [0, "desc"] 
 
       ] // set first column as a default sort by asc 
 
\t \t \t \t 
 
      } 
 
     }); 
 
\t \t 
 
\t \t 
 
\t \t 
 
\t \t \t $('.filter-cancel').on('click', function (e) { 
 
      \t e.preventDefault(); 
 
\t \t \t \t \t var i =$(this).attr('id'); // getting column index 
 
\t \t \t \t \t var v =$(this).val(); // getting search input value 
 
\t \t \t \t \t grid.getDataTable().columns(i).search(v).draw(); 
 
\t \t \t   
 
\t \t \t }); 
 
\t \t \t $('.date-picker .form-control').on('change', function (e) { 
 
      \t e.preventDefault(); 
 
\t \t \t \t var i =$(this).attr('id'); // getting column index 
 
\t \t \t \t \t var v =$(this).val(); // getting search input value 
 
\t \t \t \t grid.getDataTable().columns(i).search(v).draw(); 
 
      }) 
 
\t \t \t $('.form-filter').on('keyup', function() { 
 
\t \t \t \t var i =$(this).attr('id'); 
 
\t \t \t \t var v =$(this).val(); 
 
\t \t \t \t grid.getDataTable().columns(i).search(v).draw(); 
 
\t \t \t \t \t \t \t //alert(v);   
 
\t \t \t }); 
 
\t \t \t grid.getTableWrapper().on('click', '.filter-submit', function (event) { 
 
      \t event.preventDefault(); 
 
\t \t \t \t \t \t grid.getDataTable().ajax.reload(); // redrawing datatable 
 
\t \t \t \t \t \t grid.clearAjaxParams();   
 
\t \t \t }); 
 
\t \t \t $(".select_id").on("change", function(e, data) { 
 
\t \t \t \t e.preventDefault(); 
 
\t \t \t \t value = this.value ; 
 
\t \t \t \t var i =$(this).attr('id'); // getting column index 
 
\t \t \t \t var v =$(this).val(); // getting search input value 
 
\t \t \t \t grid.getDataTable().columns(i).search(v).draw(); 
 
\t \t \t \t //alert(v); 
 
\t \t \t }); 
 
\t 
 
     // handle group action submit button click 
 
     grid.getTableWrapper().on('click', '.table-group-action-submit', function (e) { 
 
      e.preventDefault(); 
 
      var action = $(".table-group-action-input", grid.getTableWrapper()); 
 
      if (action.val() != "" && grid.getSelectedRowsCount() > 0) { 
 
       grid.setAjaxParam("customActionType", "group_action"); 
 
       grid.setAjaxParam("customActionName", action.val()); 
 
       grid.setAjaxParam("id", grid.getSelectedRows()); 
 
       grid.setAjaxParam("data_ids", grid.getSelectedRows()); 
 
\t \t \t \t \t if (action.val() == "deleted") { 
 
       \t \t if (confirm("Apakah anda yakin akan menghapus data ini ?") == false) { 
 
       \t \t return; 
 
\t \t \t \t \t \t } 
 
\t \t    } 
 
\t \t \t \t \t \t var ids = []; 
 
\t \t \t \t \t \t $('.pilih_data').each(function(){ 
 
\t \t \t \t \t \t \t if($(this).is(':checked')) { 
 
\t \t \t \t \t \t \t \t ids.push($(this).val()); 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t }); 
 
\t \t \t \t \t \t var ids_string = ids.toString(); 
 
\t \t \t \t \t \t $.ajax({ 
 
\t \t \t \t \t \t \t type: "POST", 
 
\t \t \t \t \t \t \t url: "?route=ajaxTableContent",//dataTable, 
 
\t \t \t \t \t \t \t data: {data_ids:ids_string,status: action.val()}, 
 
\t \t \t \t \t \t \t success: function(result) { 
 
\t \t \t \t \t \t \t \t grid.getDataTable().ajax.reload(); // redrawing datatable 
 
\t \t \t \t \t \t \t \t grid.clearAjaxParams(); 
 
\t \t \t \t \t \t \t }, 
 
\t \t \t \t \t \t \t async:false 
 
\t \t \t \t \t \t }); 
 
\t \t \t \t \t \t 
 
\t \t \t \t 
 
      } else if (action.val() == "") { 
 
       Metronic.alert({ 
 
        type: 'danger', 
 
        icon: 'warning', 
 
        message: 'Please select an action', 
 
        container: grid.getTableWrapper(), 
 
        place: 'prepend' 
 
       }); 
 
      } else if (grid.getSelectedRowsCount() === 0) { 
 
       Metronic.alert({ 
 
        type: 'danger', 
 
        icon: 'warning', 
 
        message: 'No record selected', 
 
        container: grid.getTableWrapper(), 
 
        place: 'prepend' 
 
       }); 
 
      } 
 
     }); 
 
\t \t 
 
\t \t 
 
\t \t grid.getTableWrapper().on('click', '.disable', function (e) { 
 
      e.preventDefault(); 
 
\t \t \t \t \t var actions \t = jQuery(this).attr("id"); 
 
\t \t \t \t \t var ids_string = jQuery(this).attr("data-id"); 
 
\t \t \t \t \t \t $.ajax({ 
 
\t \t \t \t \t \t \t type: "POST", 
 
\t \t \t \t \t \t \t url: dataTable, 
 
\t \t \t \t \t \t \t data: {data_ids:ids_string,status: actions}, 
 
\t \t \t \t \t \t \t success: function(result) { 
 
\t \t \t \t \t \t \t \t grid.getDataTable().ajax.reload(); // redrawing datatable 
 
\t \t \t \t \t \t \t \t grid.clearAjaxParams(); 
 
\t \t \t \t \t \t \t \t //alert(result); 
 
\t \t \t \t \t \t \t }, 
 
\t \t \t \t \t \t \t async:false 
 
\t \t \t \t \t \t }); 
 
\t \t \t \t \t 
 
     \t }); 
 
\t \t 
 
\t \t grid.getTableWrapper().on('click', '.enable', function (e) { 
 
      e.preventDefault(); 
 
\t \t \t \t \t var actions \t = jQuery(this).attr("id"); 
 
\t \t \t \t \t var ids_string = jQuery(this).attr("data-id"); 
 
\t \t \t \t \t \t $.ajax({ 
 
\t \t \t \t \t \t \t type: "POST", 
 
\t \t \t \t \t \t \t url: dataTable, 
 
\t \t \t \t \t \t \t data: {data_ids:ids_string,status: actions}, 
 
\t \t \t \t \t \t \t success: function(result) { 
 
\t \t \t \t \t \t \t \t grid.getDataTable().ajax.reload(); // redrawing datatable 
 
\t \t \t \t \t \t \t \t grid.clearAjaxParams(); 
 
\t \t \t \t \t \t \t \t //alert(result); 
 
\t \t \t \t \t \t \t }, 
 
\t \t \t \t \t \t \t async:false 
 
\t \t \t \t \t \t }); 
 
     \t }); 
 
\t \t 
 
\t \t grid.getTableWrapper().on('click', '.deleted', function (e) { 
 
      e.preventDefault(); 
 
    \t \t \t \t \t var get_url = jQuery(this).attr("href"); 
 
\t \t \t \t \t var actions \t = jQuery(this).attr("id"); 
 
\t \t \t \t \t var ids_string = jQuery(this).attr("data-id"); 
 
       \t if (confirm("Apakah anda yakin akan menghapus data ini ?") == false) { 
 
\t \t \t \t \t \t return; 
 
\t \t \t \t \t } 
 
\t \t \t \t \t $.ajax({ 
 
\t \t \t \t \t \t \t type: "POST", 
 
\t \t \t \t \t \t \t url: dataTable, 
 
\t \t \t \t \t \t \t data: {data_ids:ids_string,status: actions}, 
 
\t \t \t \t \t \t \t success: function(result) { 
 
\t \t \t \t \t \t \t \t //grid.getDataTable().columns(i).search(v).draw(); 
 
\t \t \t \t \t \t \t \t grid.getDataTable().draw(); // redrawing datatable 
 
\t \t \t \t \t \t \t \t //grid.clearAjaxParams(); 
 
\t \t \t \t \t \t \t \t //alert(result); 
 
\t \t \t \t \t \t \t }, 
 
\t \t \t \t \t \t \t async:false 
 
\t \t \t \t \t \t }); 
 
     }); 
 
\t 
 
\t \t \t \t 
 
    } 
 

 
    return { 
 

 
     //main function to initiate the module 
 
     init: function() { 
 

 
      handleData(); 
 
      initPickers(); 
 
      
 
     } 
 

 
    }; 
 

 
}();
<!-- Begin: life time stats --> 
 
\t \t \t \t \t <div class="portlet light"> 
 
\t \t \t \t \t \t <div class="portlet-title"> 
 
\t \t \t \t \t \t \t <div class="caption"> 
 
\t \t \t \t \t \t \t \t <i class="fa fa-folder"></i>Pengaturan Content 
 
\t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t \t <div class="actions btn-set"> 
 
           
 
\t \t \t \t \t \t \t \t \t <button type="button" name="back" class="btn default"><i class="fa fa-angle-left"></i> Back</button> 
 
            <a class="btn btn-primary" href="?route=content&edit"><i class="fa fa-plus-circle"></i> Tambah</a> 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t <div class="portlet-body"> 
 
\t \t \t \t \t \t \t <div class="table-container"> 
 
\t \t \t \t \t \t \t \t <div class="table-actions-wrapper"> 
 
\t \t \t \t \t \t \t \t \t <span> 
 
            
 
\t \t \t \t \t \t \t \t \t </span> 
 
\t \t \t \t \t \t \t \t \t <select class="table-group-action-input form-control input-inline input-small input-sm"> 
 
\t \t \t \t \t \t \t \t \t \t <option value="">Select...</option> 
 
\t \t \t \t \t \t \t \t \t \t <option value="publish">Publish</option> 
 
\t \t \t \t \t \t \t \t \t \t <option value="unpublished">Un-publish</option> 
 
\t \t \t \t \t \t \t \t \t \t <option value="deleted">Deleted</option> 
 
\t \t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t \t \t <button class="btn btn-sm yellow table-group-action-submit" data-href="?route=ajaxUpdateContent"><i class="fa fa-check"></i> Submit</button> 
 
\t \t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t \t <table class="table table-striped table-bordered table-hover" id="datatable_content"> 
 
\t \t \t \t \t \t \t \t <thead> 
 
\t \t \t \t \t \t \t \t <tr role="row" class="heading"> 
 
\t \t \t \t \t \t \t \t \t <th width="1%"> 
 
            
 
\t \t \t \t \t \t \t \t \t \t <input type="checkbox" class="group-checkable"> 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="5%"> 
 
\t \t \t \t \t \t \t \t \t \t ID 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="40%"> 
 
\t \t \t \t \t \t \t \t \t \t Title 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="10%"> 
 
\t \t \t \t \t \t \t \t \t \t Category 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="5%"> 
 
\t \t \t \t \t \t \t \t \t \t Posted By 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="5%" class="center"> 
 
\t \t \t \t \t \t \t \t \t \t Order 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="40%"> 
 
\t \t \t \t \t \t \t \t \t \t Date 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="5%"> 
 
\t \t \t \t \t \t \t \t \t \t Status 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t \t <th width="25%"> 
 
\t \t \t \t \t \t \t \t \t \t Actions 
 
\t \t \t \t \t \t \t \t \t </th> 
 
\t \t \t \t \t \t \t \t </tr> 
 
\t \t \t \t \t \t \t \t <tr role="row" class="filter"> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <input type="text" id="0" class="form-control form-filter input-sm" name="id" placeholder="ID"> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <input type="text" autocomplete="off" id="1" class="form-control form-filter input-sm t" name="title" placeholder="Title"> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <select id="2" name="product_category" class="select_id form-control form-filter input-sm"> 
 
\t \t \t \t \t \t \t \t \t \t <?php 
 
\t \t \t \t \t \t \t \t \t \t \t $query_p = mysqli_query($con, "SELECT * FROM categories where parent=0"); 
 
\t \t \t \t \t \t \t \t \t \t \t \t echo '<option value="0"> Kategori </option>'; 
 
\t \t \t \t \t \t \t \t \t \t \t \t while ($tp = mysqli_fetch_array($query_p)) 
 
\t \t \t \t \t \t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t \t \t echo "<option value='$tp[cat_id]' >$tp[title]</option>"; 
 
\t \t \t \t \t \t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t \t \t \t \t \t ?> 
 
\t \t \t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <div class="margin-bottom-5"> 
 
\t \t \t \t \t \t \t \t \t \t \t <input type="text" id="3" class="form-control form-filter input-sm" name="posted_by" placeholder="Posted By"/> 
 
\t \t \t \t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <div class="margin-bottom-5"> 
 
\t \t \t \t \t \t \t \t \t \t \t <input type="text" id="4" class="form-control form-filter input-sm" name="order_id" placeholder="Order"/> 
 
\t \t \t \t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <div class="input-group date date-picker margin-bottom-5" data-date-format="dd-mm-yyyy"> 
 
\t \t \t \t \t \t \t \t \t \t \t <input type="text" id="5" class="t form-control form-filter input-sm" readonly name="date_created" placeholder="From"> 
 
\t \t \t \t \t \t \t \t \t \t \t <span class="input-group-btn"> 
 
\t \t \t \t \t \t \t \t \t \t \t <button class="btn btn-sm default" type="button"><i class="fa fa-calendar"></i></button> 
 
\t \t \t \t \t \t \t \t \t \t \t </span> 
 
\t \t \t \t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <select name="product_status" id="6" class="select_id form-control form-filter input-sm"> 
 
\t \t \t \t \t \t \t \t \t \t \t <option value="">Select...</option> 
 
\t \t \t \t \t \t \t \t \t \t \t <option value="yes">Published</option> 
 
\t \t \t \t \t \t \t \t \t \t \t <option value="no">Not Published</option> 
 
\t \t \t \t \t \t \t \t \t \t </select> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t \t <td> 
 
\t \t \t \t \t \t \t \t \t \t <div class="margin-bottom-5"> 
 
\t \t \t \t \t \t \t \t \t \t \t <button class="btn btn-xs yellow filter-submit margin-bottom"><i class="fa fa-search"></i> Search</button> 
 
\t \t \t \t \t \t \t \t \t \t 
 
\t \t \t \t \t \t \t \t \t \t <button class="btn btn-xs red filter-cancel"><i class="fa fa-times"></i> Reset</button> 
 
             </div> 
 
\t \t \t \t \t \t \t \t \t </td> 
 
\t \t \t \t \t \t \t \t </tr> 
 
\t \t \t \t \t \t \t \t </thead> 
 
\t \t \t \t \t \t \t \t <tbody> 
 
\t \t \t \t \t \t \t \t </tbody> 
 
\t \t \t \t \t \t \t \t </table> 
 
\t \t \t \t \t \t \t </div> 
 
\t \t \t \t \t \t </div> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t \t <!-- End: life time stats -->

+1

請添加一些文字,以幫助解釋您的答案,除了代碼。 –

0

ajaxTableContent.php 科德:

<?php 
 
/* 
 
* @author Jasriadi 
 
* @copyright © 2015 riauweb.com 
 
* 
 
*/ 
 

 

 
if ($_POST['data_ids']){ 
 
\t \t $data_ids = $_POST['data_ids']; 
 
\t \t $data_id_array = explode(",", $data_ids); 
 
\t \t $status =$_POST['status']; 
 
\t \t if($status=='publish'){ 
 
\t \t \t if(!empty($data_id_array)) { 
 
\t \t \t \t foreach($data_id_array as $id) { 
 
\t \t \t \t \t $query = "UPDATE content SET tool_show='yes' WHERE id='$id'"; 
 
\t \t \t \t \t $result = mysqli_query($con,$query); 
 
\t \t \t \t \t echo $id; 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t }else if($status=='unpublished'){ 
 
\t \t \t if(!empty($data_id_array)) { 
 
\t \t \t \t foreach($data_id_array as $id) { 
 
\t \t \t \t \t $query = "UPDATE content SET tool_show='no' WHERE id='$id'"; 
 
\t \t \t \t \t $result = mysqli_query($con,$query); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t }else if($status=='deleted'){ 
 
\t \t \t if(!empty($data_id_array)) { 
 
\t \t \t \t foreach($data_id_array as $id) { 
 
\t \t \t \t \t 
 
\t \t \t \t \t 
 
\t \t \t \t \t $query = "DELETE FROM `content` WHERE id='$id'"; 
 
\t \t \t \t \t $result = mysqli_query($con,$query); 
 
\t \t \t \t } 
 
\t \t \t } 
 
\t \t } 
 
\t \t 
 
} 
 

 

 
// storing request (ie, get/post) global array to a variable 
 
$requestData= $_REQUEST; 
 

 
$columns = array( 
 
// datatable column index => database column name 
 
\t 0 => 'id', 
 
\t 1 => 'title', 
 
\t 2 => 'cat_id', 
 
\t 3 => 'posted_by', 
 
\t 4 => 'tool_no', 
 
\t 5 => 'date_created', 
 
\t 6 => 'tool_show' 
 
); 
 

 

 

 
// getting total number records without any search 
 
$sql = "SELECT id"; 
 
$sql.=" FROM content"; 
 
$query=mysqli_query($con, $sql) or die("employee-grid-data.php: get employees"); 
 
$totalData = mysqli_num_rows($query); 
 
$totalFiltered = $totalData; // when there is no search parameter then total number rows = total number filtered rows. 
 

 

 
$sql = "SELECT `id`, `title`, `description`, `cat_id`, `tool_url`, `uid`, `icon_name`, `meta_title`, `meta_des`, `meta_tags`, `about_tool`, `tool_show`, `tool_no`, `tool_login`, `posted_by`, date_created, `headline` "; 
 
$sql.=" FROM content WHERE 1=1"; 
 

 

 
if(!empty($requestData['columns'][0]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][0]['search']['value']) ? trim($requestData['columns'][0]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND id LIKE '%$q%' ";  
 
} 
 
if(!empty($requestData['columns'][1]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][1]['search']['value']) ? trim($requestData['columns'][1]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND title LIKE '%$q%' "; 
 
} 
 
if(!empty($requestData['columns'][2]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][2]['search']['value']) ? trim($requestData['columns'][2]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND cat_id LIKE '%$q%' "; 
 
} 
 
if(!empty($requestData['columns'][3]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][3]['search']['value']) ? trim($requestData['columns'][3]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND posted_by LIKE '%$q%' "; 
 
} 
 
if(!empty($requestData['columns'][4]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][4]['search']['value']) ? trim($requestData['columns'][4]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND tool_no LIKE '%$q%' "; 
 
} 
 
if(!empty($requestData['columns'][5]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][5]['search']['value']) ? trim($requestData['columns'][5]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND date_created LIKE '%$q%' "; 
 
} 
 
if(!empty($requestData['columns'][6]['search']['value'])){ 
 
\t $q = isset($requestData['columns'][6]['search']['value']) ? trim($requestData['columns'][6]['search']['value']) :""; 
 
\t $q = searchMe($q); 
 
\t $sql.=" AND tool_show LIKE '%$q%' "; 
 
} 
 

 
$query=mysqli_query($con, $sql) or die("employee-grid-data.php: get employees"); 
 
$totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
 
$sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]." ".$requestData['order'][0]['dir']." LIMIT ".$requestData['start']." ,".$requestData['length']." "; 
 
/* $requestData['order'][0]['column'] contains column index, $requestData['order'][0]['dir'] contains order such as asc/desc */ \t 
 
$query=mysqli_query($con, $sql) or die("employee-grid-data.php: get employees1"); 
 
\t 
 

 
$data = array(); 
 
while($row=mysqli_fetch_array($query)) { // preparing an array 
 
\t $nestedData=array(); 
 
\t $toolActive = filter_var($row["tool_show"], FILTER_VALIDATE_BOOLEAN); 
 
     if($toolActive){ 
 
      $toolActive = "<span class='label label-sm label-success'>Active</span>"; 
 
      $toolActiveBut = '<a href="?route=content&id='.$row["id"].'&edit" class="btn btn-xs blue"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-xs yellow btn-danger btn-sm disable" href="?route=ajaxUpdateContent&data_ids='.$row["id"].'&disable" id="unpublished" data-id="'.$row["id"].'">Disable</a>'; 
 
      }else{ 
 
      $toolActive = "<span class='label label-sm label-info'>Not Active</span>"; 
 
      $toolActiveBut = '<a href="?route=content&id='.$row["id"].'&edit" class="btn btn-xs blue"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-xs green btn-success enable" href="?route=ajaxUpdateContent&data_ids='.$row["id"].'&enable" id="publish" data-id="'.$row["id"].'">Enable</a>'; 
 
      } 
 
\t $category \t = GETCONTENT::getCategories($con, $row["cat_id"]); 
 
\t $nestedData[] = '<input type="checkbox" class="pilih_data" name="id[]" value="'.$row["id"].'">'; 
 
\t $nestedData[] = $row["id"]; 
 
\t $nestedData[] = $row["title"]; 
 
\t $nestedData[] = $category["title"]; 
 
\t $nestedData[] = $row["posted_by"]; 
 
\t $nestedData[] = $row["tool_no"]; 
 
\t $nestedData[] = $row["date_created"]; 
 
\t $nestedData[] = ''.$toolActive.''; 
 
\t $nestedData[] = ' 
 
\t '.$toolActiveBut.'<a href="../news/'.$row["tool_url"].'" target="_blank" class="btn btn-xs blue"><i class="fa fa-search"></i> View</a> 
 
\t '; 
 
\t 
 
\t $data[] = $nestedData; 
 
} 
 

 
$json_data = array(
 
\t \t \t "draw"   => intval($requestData['draw']), // for every request/draw Data 
 
\t \t \t "recordsTotal" => intval($totalData), // total number of records 
 
\t \t \t "recordsFiltered" => intval($totalFiltered), // Pencarian Data 
 
\t \t \t "data"   => $data // total data array 
 
\t \t \t); 
 
if (isset($_REQUEST["customActionType"]) && $_REQUEST["customActionType"] == "group_action") { 
 
$statusAction = $_REQUEST['customActionName'];//Type Publish 
 
$json_data["customActionStatus"] = "OK"; // pass custom message(useful for getting status of group actions) 
 
$json_data["customActionMessage"] = ' Data successfully has been '.$statusAction.' completed. Well ok!'; 
 
    
 
    } 
 
echo json_encode($json_data); // send data as json format 
 

 
?>

相關問題