I'm building an intake application for clubs. I'm having trouble getting the user from one page to another. Each page is a module, usually a form. And they can differ in position, as in the user can change the position a page has in the intake.
Here's how my database looks like approximately. A club can have 1 or more intakes. An intake consists of multiple modules. The database models look like this:
table: intake
intake_id(P) club_id
12345 99999
12346 99999
12347 99998
table: intake_has_module
intake_id(P) module_id position
12345 1 2
12345 2 1
12345 3 3
12346 1 1
12346 2 2
etc.
table: module
module_id(P) name
1 Personal Information
2 Terms and Conditions
3 Subscriptions
(Dummy data)
Here I get the intake_id from the corresponding club
$intake_sql = $db->sql_query('SELECT intake_id FROM fit_vg_intake WHERE club_id = ' . (int)User::currentUser()->getClubID());
$intake_sql_2 = $db->sql_fetchrow($intake_sql);
Here I get the module_id that's in first position from the club's intake
$module_sql = $db->sql_query('SELECT module_id FROM fit_vg_intake_has_module WHERE position = 1 AND intake_id = ' . $intake_sql_2['intake_id']);
$module_sql_2 = $db->sql_fetchrow($module_sql);
Then I use this module_id in a switch that looks like this:
switch ($module_sql_2['module_id']) {
case 1:
generate_page('intake/personalinformation.twig');
break;
case 2:
generate_page('intake/termsandconditions.twig');
break;
case 3:
generate_page('intake/subscriptions.twig');
break;
default:
generate_page('intake/main.twig');
break;
}
So this part is working correctly for me. The user can switch the position of each module in a settings panel. Now for my problem & question:
Say a user is on the Terms and Conditions module. Which is module_id 2 and position 1. When he clicks a button which confirms that he has accepted the terms and conditions he should be moved to the module that has the position+1 of module_id=2.
What I've tried: I've tried adding an onClick to the button. When clicked on a javascript function gets called named next_module() with an action called accepted-terms. I pass this action to the php file in which I use another switch:
switch ($action) {
case 'accepted-terms':
$position_sql = $db->sql_query('SELECT position FROM intake_has_module WHERE module_id = 2 AND intake_id = ' . $intake_sql_2['intake_id']);
$position_sql_2 = $db->sql_fetchrow($position_sql);
break;
default:
break;
}
In this switch as you can see I get the position of the module with module_id=2. It returns 1 which is correct. Now I can get the module_id with a position of 1+1. This is how far I've come. Basically my question is: How do I return to the first switch with the new module_id when someone clicks a button?