问题描述
我在数据库中有一张名为“发票”的表格,其中列有“自动月份”和“自动年份”及其值。我不知道为什么这个函数返回空数组。我想获取具有自动月份值和自动年份值的行。请帮助我。
$autoyear = date('Y');
$automonth = date('m');
$autonumber = DB::table("invoices as invoices")
->where('automonth','=','$automonth')
->where('autoyear','$autoyear')
->get();
解决方法
您以错误的方式传递了变量:
$autonumber = DB::table("invoices as invoices")
->where('automonth','=',$automonth)
->where('autoyear',$autoyear)
->get();
当您传递变量名时不需要'...
,从 $ automonth 和 $ autoyear 中删除报价:
$autonumber = DB::table("invoices as invoices")
->where('automonth',$autoyear)
->get();