This topic is locked

Can I change the source table for radio buttons in programme?

12/9/2008 5:06:04 AM
PHPRunner General questions
T
thesofa author

Hi

I have a survey where the questions to be asked vary with the age of the pupil completing the survey.

So when a pupil logs in, I get their age and use it to change the set of questions I ask.

Now for the fun part, the answers to these questions is a choice of 4 radio buttons, all from a table.

BUT when we have the questions for the younger kids, there are only 3 answers and they are from a different table.

How can I change the source table for the radio buttons, depending on the length of the variable stored in

$_SESSION["yg"]



so far I have used this

If(2==strlen($_SESSION["yg"]))

$question_table="v_q1";

else

$question_table="v_q1_ks3";



because the split for the questions is at the end of year 9.

The two tables for the answers are

v_ratings and v_ratings_ks3

so I was looking at something like

If(2==strlen($_SESSION["yg"]))

$choices_table="v_ratings";

else

$choices_table="v_ratings_ks3";



but how do I base the radio button source on the session variable?
Any ideas please anyone?

T
thesofa author 12/9/2008

OK, I have dug a bit more and found this in the relevant xxxx_settings.php file

q1-01

$fdata = array();

$fdata["Label"]="Q1-01";





$fdata["FieldType"]= 2;

$fdata["EditFormat"]= "Radio button";

$fdata["ViewFormat"]= "";







$fdata["LookupType"]=1;

$fdata["LinkField"]="`score`";

$fdata["LinkFieldType"]=16;

$fdata["DisplayField"]="`rating`";

$fdata["LookupTable"]="v_ratings";

$fdata["NeedEncode"]=true;



$fdata["GoodName"]= "q1_01";

$fdata["FullName"]= "`q1-01`";

$fdata["IsRequired"]=true;







$fdata["Index"]= 2;



$fdata["FieldPermissions"]=true;

$tdatav_ans_1["q1-01"]=$fdata;



There is a similar piece of code for each field that has radio buttons on this and another 2 pages.

Is it OK to put an "If" clause just before the pieces of code for all the fields along the lines of

If(2==strlen($_SESSION["yg"]))

$fdata["LookupTable"]="v_ratings";

else

$fdata["LookupTable"]="v_ratings_ks3";



and remove the line

$fdata["LookupTable"]="v_ratings";



from each field's piece of code for the 3 pages concerned?

All 3 pages have nothing other than the questions with radio button answers, and all the questions on the page will have answer choices from the same table?
OR, Should I be putting the logic in the xxxx_variables.php file and use a view to be the source of the lookup, so after the if clause, I can then base the view on $strOriginalTableName
so I would have

If(2==strlen($_SESSION["yg"]))

$strOriginalTableName="v_ratings";

else

$strOriginalTableName="v_ratings_ks3";



and do a similar one for the

$gsqlFrom="FROM v_ans ";



line?
But as the page is based on a custom view I would then have 2 lots of the same variables......

Should I make the PHPR custom views into hard coded views in MySQL?

T
thesofa author 12/10/2008

Update to this problem.

Ok, I have tried all of the above ideas without success, so I sat and rethought the problem.

I added another column in my table where I get the answers from, i.e. v_ratings.

I now have a column called `ks`, tinyint, length1, not null. This holds either a 3 or a 4, depending on the Key Stage of the kid.

The older kids are in Key Stage 4 and the younger ones are in Key Stage 3

KS4 is years 10 and 11

KS3 is years 7,8,and 9

so where I have this code

If(2==strlen($_SESSION["yg"]))

$question_table="v_q1";

else

$question_table="v_q1_ks3";


I have now changed it to read

If(2==strlen($_SESSION["yg"]))

{

$question_table="v_q1";

$key_stage=4;

}

else

{

$question_table="v_q1_ks3";

$key_stage=3;

}



and I have added

$_SESSION["key_stage"]=$key_stage;



at the end of the BeforeProcessAdd function

then in the 'Where' clause box in the radio button lookup dialogue in the Visual Editor, I have used

"`ks`=".$_SESSION["key_stage"]


AND IT WORKS
WOOOOOOOOOOOOOOOOOOOOHOOOOOOOOOOOOOOOO

so KS4 kids get the more difficult questions with 4 answers and the KS3 kids get the simplified questions and the restricted range of answers.
SCORE
if you need more details, just ask and I will try to help