Yii Framework Forum: Variable Variable In Active Record - Yii Framework Forum

Jump to content

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

Variable Variable In Active Record Rate Topic: -----

#1 User is offline   Vipin C 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 09-November 12

Posted 19 November 2012 - 01:58 AM

Hi,
How do I handle Variable Variable($$) in Active Record output?

For Ex.

$qdata = $qmodel->findByAttributes(array("q_id"=>$testqs[0]->q_id));
$qcorrect = "answer".$qdata->correct_answer;

I need $qdata->answer1. But the value 1 is dynamic based on what is passed.

$qdata->$$qcorrect does not work.

Thanks,
Vipin
0

#2 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 873
  • Joined: 20-April 11
  • Location:India

Posted 19 November 2012 - 02:42 AM

didnt get ur doubt!!

anyway u need this? $qdata->qcorrect ?

after this , $qdata = $qmodel->findByAttributes(array("q_id"=>$testqs[0]->q_id));

$qdata is an array..u can use like ,$qdata->q_id, $qdata->ur_attribute_here etc...
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#3 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 781
  • Joined: 02-July 10
  • Location:Central Poland

Posted 19 November 2012 - 02:52 AM

View PostVipin C, on 19 November 2012 - 01:58 AM, said:

Hi,
How do I handle Variable Variable($$) in Active Record output?

For Ex.

$qdata = $qmodel->findByAttributes(array("q_id"=>$testqs[0]->q_id));
$qcorrect = "answer".$qdata->correct_answer;

I need $qdata->answer1. But the value 1 is dynamic based on what is passed.

$qdata->$$qcorrect does not work.

Thanks,
Vipin

you should use it like this:
$qdata->$qcorrect; //only one $ sign if $qcorrect variable holds the attribute name.

red
0

#4 User is offline   Ujjwal Prajapati 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 47
  • Joined: 24-April 12

Posted 19 November 2012 - 05:34 AM

Your post does not seem to be much clear as to what is $qdata - answer1 and you mean 1 is the variable passed. Anyway, whatever you are trying to get from the query if the value is the column value in the database; that should be easily fetched as $qdata -> column_name. or iterate foreach loop as the result is the array.
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