如何自动增加账单号

时间:2018-10-24 12:09:28

标签: php codeigniter

设计页面代码:

<input type="text" class="form-control "  placeholder="Bill.No"name="billno" id="AcNo" value="" required>

Ajax代码:

<script type="text/javascript">

    $(document).ready(function(){

        $.ajax({
            type: "POST",
            url: "<?php echo base_url();?>TipUp_Loan/get_AcNo",
            data:{id:$(this).val()},
            datatype:'json',
            success: function (data) {
                var res = jQuery.parseJSON(data);
                $("#AcNo").val(res);
                    alert(ok);

            }
        });

    });

</script>

控制器代码:

public function get_AcNo()
{
    $query = $this->db->query('SELECT MAX(no) AS `AcNo` FROM `salesbill` ORDER BY no DESC LIMIT 1')->row_array();

        //print_r($query);
    if($query['AcNo'] == "")
    {
        $message = 1;
    }
    else
    {
        $message = $query['AcNo']+1;
    }

    echo json_encode ($message); 
}

我的问题是帐单编号不断显示2提交表格后如何自动增加帐单编号

3 个答案:

答案 0 :(得分:2)

尝试这个



    $(document).ready(function(){

        $.ajax({
            type: "POST",
            url: "TipUp_Loan/get_AcNo",
            data:{id:$(this).val()},
            datatype:'json',
            success: function (data) {
                $("#AcNo").val(data);
                    alert(ok);
            }
        });

    });



public function get_AcNo()
{
    $query = $this->db->query('SELECT MAX(no) AS `AcNo` FROM `salesbill` ORDER BY no DESC LIMIT 1')->row_array();
    //print_r($query);

    if ($query['AcNo'] == ""){
        $message = 1;
    } else {
        $message = $query['AcNo']+1;
    }
    echo $message; 
}

答案 1 :(得分:0)

像这样编辑它

<script type="text/javascript">
    $(document).ready(function(){
        $.ajax({
            type: "POST",
            url: "<?php echo base_url();?>TipUp_Loan/get_AcNo",
            data:{id:$(this).val()},
            datatype:'json',
            success: function (data) {
                $("#AcNo").val(data);
                    alert('ok');
            }
        });
    });
</script>

public function get_AcNo()
{
    $query = $this->db->query('SELECT MAX(no) AS `AcNo` FROM `salesbill` ORDER BY no DESC LIMIT 1')->row_array();
    //print_r($query);

    if ($query['AcNo'] == ""){
        $message = 1;
    } else {
        $message = $query['AcNo']+1;
    }
    echo $message; 
}

答案 2 :(得分:0)

您可以尝试以下sql查询:   $ query = $ this-> db-> query('SELECT MAX(no)AS“ AcNo” FROM“ salesbill”')-> row_array(); 或者您也可以尝试以下查询:  $ query = $ this-> db-> query('SELECT count(no)AS“ AcNo” FROM“ salesbill”')-> row_array();