如何自动增加账单编号



设计页面代码:

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

阿贾克斯代码:

<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 提交表格后如何自动增加账单号

试试这个

$(document(.ready(function(({ $.ajax({ 类型:"开机自检", 网址: "TipUp_Loan/get_AcNo", data:{id:$(this(.val((}, 数据类型:"json", 成功:函数(数据({ $("#AcNo"(.val(data(; 警报(正常(; } }); }); 公共函数 get_AcNo(( { $query = $this->db->query('从'销售账单'订单中选择最大(否(作为'AcNo',无DESC LIMIT 1'(->row_array((; print_r($query(; if ($query['AcNo'] == "({ $message = 1; } else { $message = $query['AcNo']+1; } 回声$message; }

这样编辑

<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; 
}

你可以试试这个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((;

相关内容

  • 没有找到相关文章

最新更新