db question

Hello guys.

Please help me to solve my problem.

I have this code:

public function actionGetker()



	$komanda_id = $_POST['komanda_id'];

	$ker1 = Ker1::model()->find('predmet like :predmet and komanda_id = :komanda_id',array(':predmet'=>$predmet,':komanda_id'=>$komanda_id));



	    $data = array(

			'ker1'=>"<span style='color:#000000'>Перший керівник команди:</span><br>".$ker1->k1_prizv." ".$ker1->k1_im." ".$ker1->k1_pob,











            if($predmet == '')


		$data = array('ker1'=>"",'ker1_id'=>"");




		$data = array('ker1'=>"Додати першого керівника",'predmet'=>$predmet,'ker1_id'=>"");



    echo json_encode($data);


The problem is that sometimes $data gets no value at all. It depends on what value is assigned to $predmet.

What can be wrong? Is something wrong with this

$ker1 = Ker1::model()->find('predmet like :predmet and komanda_id = :komanda_id',array(':predmet'=>$predmet,':komanda_id'=>$komanda_id));


It seems that you are doing an Ajax call.

Try to run it directlly to see if some error occurs. There is no way to not have value at $data, so it seem to be an error on ‘find’.

I’m sorry but the code above is correct. The problem was in another plase in my code.

hi viter:

maybe this is the SQL syntext problem, if you want use SQL syntext “LIKE” to search your predmet, when you lose the “%”, the search result will not as correct as you think, so we can use CDbCriteria’s method “addSearchCondition” to add “LIKE” syntext.

$criteria = new CDbCriteria;

$criteria->condition = "t.komanda_id = :komanda_id";

$criteria->params = array(':komanda_id'=>$komanda_id);

$criteria->addSearchCondition('t.predmet', $predmet);

$ker1 = Ker1::model()->find($criteria);

hope this will help you :)

Hello hermes.

Thank you for your hint but my syntax is ok. I showed here only part of my function in which I thought there was problem. But it appeared that I had a mistake in another place and execution of my script was broken so that the part



and on was never executed.

Sorry guys for disturbing you.