简体   繁体   English

使用.getJSON传递变量进行条件SQL查询

[英]Passing a variable using .getJSON for conditional SQL Query

I have a page that generates a table and its content will be retrieved using .getJSON . 我有一个生成表的页面,其内容将使用.getJSON检索。 But i have a variable to be passed for that conditional query. 但是我有一个要传递给该条件查询的变量。 Here is my code, 这是我的代码,

<?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>

how do i post var custid = '<?php echo $cust_id; ?>'; 我如何发布var custid = '<?php echo $cust_id; ?>'; var custid = '<?php echo $cust_id; ?>'; to price_history_data.php that contains the query so that the data inside the table only shows data based on the custid variable that i send.. ? 到包含查询的price_history_data.php ,以便表中的数据仅显示基于我发送的custid变量的数据。

Thanks again for the help 再次感谢您的帮助

Here you are: 这个给你:

$.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;
    });

Pass custid as a get parameter in the URL 在URL中传递custid作为get参数

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM