tags:

views:

35

answers:

2

to get the DB result in basis of condition

if($keyword!='')
  build condition;
  /*
    array('conditions' => array("AND" => array ("esl.esl_artistname LIKE"=>"%".$artistname."%",
    "esl.esl_songname LIKE"=>"%".$songname."%")),
    'limit' => $arrFind['limit'],
    'page'=>$arrFind['page']));
  */


if(!name!='')
  /* 
    array('conditions' => array("esl.esl_artistname LIKE"=>"%".$artistname."%"),
    'limit' => $arrFind['limit'],
    'page'=>$arrFind['page'] ))
  */

$this->find('all',condition);

how to do this? how to concatinate both conditions?

please Help me!

+1  A: 

Why not initialize the conditions array and just append to it?

$conditions = array();
if( keyword != '' ) {
  array_push(
    'conditions'
    , array( "AND" => array ("esl.esl_artistname LIKE"=>"%".$artistname."%", "esl.esl_songname LIKE"=>"%".$songname."%" ) )
}

if( !name != '' ) {
   array_push( 'conditions', array("esl.esl_artistname LIKE"=>"%".$artistname."%")
}

$this->find( 'all', array( 'conditions' => $conditions, 'limit' => $arrFind['limit'], 'page' => $arrFind['page'];
Rob Wilkerson
+1  A: 

Please format your code correctly, but concatenating condition could be done in following way:

$condition1 = array('Model1.field1 LIKE'=>'%'.$value.'%', 'Model1.field2'=>2);
$condition2 = array('Model2.field2 LIKE'=>'%'.$value.'%', 'Model2.field2'=>1);

$this->MyModel->find('all', array('consitions'=>am($condition1, $condition2)));

am is the cake's shortcut to array_merge.

Nik