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
Page 1 of 1
Variable Variable In Active Record
#2
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...
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
Wiwo inc.
| Mobile: 919995504508
#3
Posted 19 November 2012 - 02:52 AM
Vipin 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
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
#4
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.
Share this topic:
Page 1 of 1

Help















