1

How can i make something:

  public function executeSearch(sfWebRequest $request)
  {
    $test = 1;

    $this->shows = Doctrine_Core::getTable('Show')
      ->createQuery('a')
      ->where('a.name = ?', 'Tom')
   if ($test == 1) {   ->andWhere('a.last_name = ?', 'Jerry') }
      ->execute();
  }

this doesn't work. How can i instruction if in Doctrine query?

OR:

  public function executeSearch(sfWebRequest $request)
  { 
    if(isset($test)){
    $test = 'Jerry';
    }
  //now if isset $test then andWhere search only with Jerry, if not isset andWhere search ALL

    $this->shows = Doctrine_Core::getTable('Show')
      ->createQuery('a')
      ->where('a.name = ?', 'Tom')
      ->andWhere('a.last_name = ?', $test) }
      ->execute();
  }

1 Answer 1

5
$q = Doctrine_Core::getTable('Show')
  ->createQuery('a')
  ->where('a.name = ?', 'Tom');

if ($test == 1) 
{   
  $q->andWhere('a.last_name = ?', 'Jerry');
}

$this->shows = $q->execute();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.