Variable Variable In Active Record

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

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…

you should use it like this:




$qdata->$qcorrect; //only one $ sign if $qcorrect variable holds the attribute name.



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.