2015-10-30 74 views
1

我有一個頁面,生成一個表,其內容將被檢索使用.getJSON。但我有一個變量要通過該條件查詢。這裏是我的代碼,傳遞一個變量使用.getJSON條件SQL查詢

<?php $cust_id = $_GET['cust_id']; ?> 
<table class="display" id="invoice-disc-list" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>INVOICE #</th> 
      <th>INVOICE DATE</th> 
      <th>SALESMAN</th> 
      <th>INVOICE AMOUNT</th> 
      <th>DISCOUNT</th> 
     </tr> 
    </thead> 
</table> 

<script> 
    $.getJSON('pages/lj_menu/monitoring/process/price_history_data.php', function(response) { 
     var custid = '<?php echo $cust_id; ?>'; 
     // Initialize DataTables 
     $('#invoice-disc-list').DataTable({ 
      iDisplayLength : 15, 
      processing: true, 
      data: response, 
      columns: [ 
       {data: "INVOICE_NO"}, 
       {data: "INVOICE_DATE"}, 
       {data: "INVOICE_SALESMAN"}, 
       {data: "INVOICE_AMOUNT"}, 
       {data: "INVOICE_DISCOUNT"} 
      ] 
     }); 

     // Initialize AJAX onClick Data Send 
     window.someGlobalOrWhatever = response.balance; 
    }); 
</script> 

如何發佈var custid = '<?php echo $cust_id; ?>';price_history_data.php,使表裏面的數據只顯示了基於custid變量,我將數據發送包含查詢..?再次

感謝您的幫助

+2

通GET參數** **客戶ID作爲GET參數 –

+0

你是什​​麼意思 ?以及如何做到這一點? –

+1

像這樣'$ .getJSON(「pages/lj_menu/monitoring/process/price_history_data.php?custid = <?php echo $ cust_id;?>」,function(response)' –

回答

1

custid作爲URL

<?php $cust_id = $_GET['cust_id']; ?> 
<table class="display" id="invoice-disc-list" cellspacing="0" width="100%"> 
    <thead> 
     <tr> 
      <th>INVOICE #</th> 
      <th>INVOICE DATE</th> 
      <th>SALESMAN</th> 
      <th>INVOICE AMOUNT</th> 
      <th>DISCOUNT</th> 
     </tr> 
    </thead> 
</table> 

<script> 
    $.getJSON('pages/lj_menu/monitoring/process/price_history_data.php?custid=<?php echo $cust_id; ?>', function(response) { 
     var custid = '<?php echo $cust_id; ?>'; 
     // Initialize DataTables 
     $('#invoice-disc-list').DataTable({ 
      iDisplayLength : 15, 
      processing: true, 
      data: response, 
      columns: [ 
       {data: "INVOICE_NO"}, 
       {data: "INVOICE_DATE"}, 
       {data: "INVOICE_SALESMAN"}, 
       {data: "INVOICE_AMOUNT"}, 
       {data: "INVOICE_DISCOUNT"} 
      ] 
     }); 

     // Initialize AJAX onClick Data Send 
     window.someGlobalOrWhatever = response.balance; 
    }); 
</script> 
1

給你:

$.getJSON('pages/lj_menu/monitoring/process/price_history_data.php', '<?php echo $cust_id; ?>') 
    .done(function(response) { 
     // Initialize DataTables 
     $('#invoice-disc-list').DataTable({ 
      iDisplayLength : 15, 
      processing: true, 
      data: response, 
      columns: [ 
       {data: "INVOICE_NO"}, 
       {data: "INVOICE_DATE"}, 
       {data: "INVOICE_SALESMAN"}, 
       {data: "INVOICE_AMOUNT"}, 
       {data: "INVOICE_DISCOUNT"} 
      ] 
     }); 

     // Initialize AJAX onClick Data Send 
     window.someGlobalOrWhatever = response.balance; 
    });