Yii Framework Forum: db question - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

db question please help! Rate Topic: -----

#1 User is offline   viter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 21-January 10
  • Location:Ukraine Ivano-Frankivsk

Posted 27 October 2010 - 05:32 AM

Hello guys.
Please help me to solve my problem.
I have this code:
public function actionGetker()
{
	$predmet=$_POST['predmet'];
	$komanda_id = $_POST['komanda_id'];
	$ker1 = Ker1::model()->find('predmet like :predmet and komanda_id = :komanda_id',array(':predmet'=>$predmet,':komanda_id'=>$komanda_id));
	if(isset($ker1))
	{
	    $data = array(
			'ker1'=>"<span style='color:#000000'>Перший керівник команди:</span><br>".$ker1->k1_prizv." ".$ker1->k1_im." ".$ker1->k1_pob,
			'predmet'=>$predmet,
			'ker1_id'=>$ker1->id,
			'k1_prizv'=>$ker1->k1_prizv,
			'k1_im'=>$ker1->k1_im,
			'k1_pob'=>$ker1->k1_pob,
			'k1_posada'=>$ker1->posada
			);
	}
	else
	{
            if($predmet == '')
	    {
		$data = array('ker1'=>"",'ker1_id'=>"");
	    }
	    else
	    {
		$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));

Thanks.
0

#2 User is offline   ricardograna 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 376
  • Joined: 31-March 09
  • Location:Manaus/AM - Brazil

Posted 27 October 2010 - 09:17 AM

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'.
Yes, It Is!
0

#3 User is offline   viter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 21-January 10
  • Location:Ukraine Ivano-Frankivsk

Posted 28 October 2010 - 02:45 AM

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

#4 User is offline   hermes 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 26-April 10

Posted 28 October 2010 - 11:48 PM

View Postviter, on 28 October 2010 - 02:45 AM, said:

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 :)
0

#5 User is offline   viter 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 177
  • Joined: 21-January 10
  • Location:Ukraine Ivano-Frankivsk

Posted 29 October 2010 - 01:44 AM

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
if(isset($ker1))
{...}

and on was never executed.
Sorry guys for disturbing you.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users