使用codeigniter get_where函数创建查询以获取特定数据时遇到问题。我阅读并理解了手册并在我的代码中使用了它,但现在当我要从数据库中查询时,如下面的代码,它不起作用。
型号:
public function load_parents () {
$query = $this->db->get_where('checklist_items', array(('checklist_id' => $checklist_id) && ('parent_id' => $parent_id)));
$result = $query->result_array ();
return $result;
}
错误: 消息:语法错误,意外'=>' (T_DOUBLE_ARROW),期待')'
我知道代码不对,但有另一种方法可以让它运行吗?
答案 0 :(得分:1)
使用
Option Explicit
Sub main()
Dim iLoop As Long, jLoop As Long
Dim lastRow As Long, countRow As Long
Dim myDate1 As Variant, myDate2 As Variant
lastRow = Sheet1.Range("A" & Rows.Count).End(xlUp).Row
For iLoop = 1 To lastRow
countRow = Application.CountIf(Sheet1.Range(Sheet1.Cells(iLoop, 1), Sheet1.Cells(lastRow, 1)), Sheet1.Cells(iLoop, 1))
If countRow > 2 Then
For jLoop = lastRow To (iLoop + 1) Step -1
If Sheet1.Cells(jLoop, 1).Value = Sheet1.Cells(iLoop, 1).Value Then
myDate1 = Application.EDate(Sheet1.Cells(iLoop, 2), 3)
myDate2 = Sheet1.Cells(jLoop, 2)
If myDate2 > myDate1 Then Sheet1.Cells(jLoop, 3).Resize(1, 2) = Array("1", "3")
Exit For
End If
Next jLoop
End If
Next iLoop
End Sub
答案 1 :(得分:1)
使用它:
<?php
public function load_parents ()
{
$query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id, 'parent_id' => $parent_id));
$result = $query->result_array ();
return $result;
}
?>
答案 2 :(得分:1)
尝试使用此代码
public function load_parents () {
$query = $this->db->get_where('checklist_items', array('checklist_id' => $checklist_id , 'parent_id' => $parent_id));
$result = $query->result_array ();
return $result;
}
您无法在数组中使用&&
。
它会自动考虑and
。
另一种方法是使用
之类的地方public function load_parents () {
$query = $this->db
->where('checklist_id' => $checklist_id)
->where('parent_id' => $parent_id)
->get('checklist_items');
$result = $query->result_array();
return $result;
}