0

I get my data by this way:

$table = new Application_Model_DbTable_FooBar();

$data = $table
->select()
->where('id = ?', (int) $id)
->query()
->fetchAll();

and want to add a separate where clause in an if() statement.
Something like that:

if($foo == "bar") {
    $data->where('foo = ?, 'bar');
}

So I tried something like that, but it didn't work.

$table = new Application_Model_DbTable_FooBar();

$table
->select()
->where('id = ?', (int) $id);

if($foo == "bar") {
    $table->where('foo = ?, 'bar');
}

$data = $table->query()->fetchAll();
Mischa
  • 1,073
  • 2
  • 13
  • 23

1 Answers1

1

try this

$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();
Sergey Krivov
  • 372
  • 1
  • 4