如何在Codeigniter中找到最后一个账单号

时间:2018-10-27 12:10:41

标签: php codeigniter

我的问题是我想使用最近的帐单编号显示最后一个帐单条目,并尝试使用max(no),但我收到错误严重性:注意

  

消息:数组到字符串的转换

文件名:database / DB_query_builder.php

行号:669

回溯:

  

文件:D:\ xampp \ htdocs \ Yuva \ application \ models \ User_model.php行:212   功能:其中

     

文件:D:\ xampp \ htdocs \ Yuva \ application \ controllers \ Inventory.php行:   70函数:Bill_Last1

     

文件:D:\ xampp \ htdocs \ Yuva \ index.php行:315功能:require_once

发生数据库错误 错误编号:1054

  

“ where子句”中的未知列“ Array”

选择*来自salesitem的左外部联接salesbillsalesbill = nosalesitem左外部联接{{1} }在billno上。parmaster = parmasterPcodesalesbill = partyname

文件名:D:/xampp/htdocs/Yuva/system/database/DB_driver.php 这是我的控制器代码:

billno

1 个答案:

答案 0 :(得分:0)

我认为您需要尝试以这种方式获得最大值,因为它返回的是数组而不是 $search变量以获取最大数量。要获取max_no,您可以使用row_array()row(),然后在max_no上使用$this->db->where('billno', $search);

  

另外,MAX(no)将返回最大值,因此无需额外   ORDER BY no clause

$search = $this->db->query('SELECT MAX(no) as max_no FROM `salesbill`')->row_array()['max_no'];

请参见参考文献https://www.codeigniter.com/userguide3/database/results.html