PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon May 25, 2020 11:51 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Fri May 13, 2016 8:51 am 
Offline
Forum Newbie

Joined: Fri May 13, 2016 8:21 am
Posts: 2
So I've been tasked with a type of review system that has 4 types of reviews. The reviews will have 15-20 questions each in them and the questions will range from basic "Yes/No" through to a Date and Location answer. The system works on rules though where it takes into account the Yes/No answers and funnels them into a rule system.

The questions are stored in the database and pulled from it, I feel like I could do the same for the rules. In all of the prototypes I've been hard coding these rules but I wanted to move to a more user friendly dynamic method.

For example you do a review on What Movies You've Seen?:

Q1) Godfather Y/N
Q2) Journey To The Center Of The Earth Y/N
Q3) Snow White Y/N
Q4) What's your favourite film? Text Entry

Now lets say the Rules are:
Rule 1 = If Q1 & Q2 are answered both Yes and the Q3 is No - GOTO Page 2.
Rule 2 = If Q1 & Q3 Are Answered Yes And Q2 are No - GOTO Page 3.

There would never be any need to take note of textboxes or anything like that, just Yes/No Radio buttons which to me just means it's a case of having a lot of 1's & 0's saved.

My question is really how would this be displayed in a front end actionable system and how would it be saved in a MySQL Database nicely so that it's retrievable later. I know it's really broad question.

I was going to have a table where you had a set of "Pages" that were given a start question value and an end question value eg:


But that denormalizes the rule data and means I'll have to split it whenever I want to edit. I don't mind that too much as it's not really data to start with and it seems simple enough but I just wanted some input on this as I don't want to jump in for it to suddenly dawn on me that there's a better way!

Cheers in advance


Top
 Profile  
 
PostPosted: Fri May 13, 2016 8:10 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13592
Location: New York, NY, US
If all you need to deal with are Yes and No, then all you need is a list of the questions that need to be Yes and a list of those that need to be No. So to restaye your rules:

Rule 1: Yes Q1, Q2; No Q3; GOTO Page 2;
Rule 2: Yes Q1, Q3; No Q2; GOTO Page 3;

The most condensed way to store those would be something like:

Rule 1: 1,2;3;2
Rule 2: 1,3;2;3

To parse
Syntax: [ Download ] [ Hide ]
$rule = explode(';', $row['rule']);
$yes = explode(',', $rule[0]);
$no = explode(',', $rule[1]);
$goto = explode(',', $rule[2]);
 

You could then generate SQL from $yes and $no. Then use $goto if you get back count($yes) + count($no) rows.

_________________
(#10850)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group