我通过这种方式得到我的数据:
$table = new Application_Model_DbTable_FooBar();
$data = $table
->select()
->where('id = ?', (int) $id)
->query()
->fetchAll();
并希望在if()语句中添加单独的where子句 这样的事情:
if($foo == "bar") {
$data->where('foo = ?, 'bar');
}
所以我尝试了类似的东西,但它没有用。
$table = new Application_Model_DbTable_FooBar();
$table
->select()
->where('id = ?', (int) $id);
if($foo == "bar") {
$table->where('foo = ?, 'bar');
}
$data = $table->query()->fetchAll();
答案 0 :(得分:1)
试试这个
$table = new Application_Model_DbTable_FooBar();
$table = $table
->select()
->where('id = ?', (int) $id);
if($foo == "bar") {
$table = $table->where('foo = ?, 'bar');
}
$data = $table->query()->fetchAll();