LunarIsSexy Posted September 20, 2013 Share Posted September 20, 2013 I have a hard question that hopefully somebody could help me with. I'm trying to make a website that teaches tutorials on certain subjects and lets just say your on page 5 in the subject "Math" and there are 20 pages in total in that subject I could just make it at the top of Page 5 set the $_SESSION = 25 for example. How would I then make it so this always automatically saves to the database but also make it so you need to be equal to or over the percentage of 50 to get to page 10/20 for example. I know that I can just do an if statement checking if the percentage is but I want to make it always automatically save to the database what percentage and I want it so that if the user signs in on a different computer it will still have the same amount of percentage. You don't have to add it but if someone were able to figure out also how to add so that when you press "Continue" on the homepage under the subject it would actually bring you to the page matching the percentage you have. I know this is a lot of work but if somebody could atleast point me in the right direction, thankyou <3 I already have a login and register system, so I could incorporate it into the users table but that might make things get confusing if I have up to 10 subjects. Quote Link to comment https://forums.phpfreaks.com/topic/282327-session-to-database/ Share on other sites More sharing options...
jcbones Posted September 20, 2013 Share Posted September 20, 2013 Just add it in on line 131. Quote Link to comment https://forums.phpfreaks.com/topic/282327-session-to-database/#findComment-1450487 Share on other sites More sharing options...
kicken Posted September 20, 2013 Share Posted September 20, 2013 Not entirely sure what you are after, but it sounds like you want to do two things 1) Prevent a person from skipping ahead in a subject (ie, before they get to page 10, they have to visit page 9) and 2) Provide a continue button that takes them to whatever page they left off on. The way to do both of those is just to track what pages the user has visited. Whenever they visit one of the pages, run a query to update a table indicating they have visited that page. To prevent skipping, you'd add some code to query the visit tracking table to make sure they have visited the previous page in the subject. If not, either show an error or maybe redirect them to their continue point. To add the continue button, you'd query that visit table for the highest page in the subject that they have visited. Then either send them to that page or the next page, depending on what you want. Quote Link to comment https://forums.phpfreaks.com/topic/282327-session-to-database/#findComment-1450491 Share on other sites More sharing options...
LunarIsSexy Posted September 20, 2013 Author Share Posted September 20, 2013 Not entirely sure what you are after, but it sounds like you want to do two things 1) Prevent a person from skipping ahead in a subject (ie, before they get to page 10, they have to visit page 9) and 2) Provide a continue button that takes them to whatever page they left off on. The way to do both of those is just to track what pages the user has visited. Whenever they visit one of the pages, run a query to update a table indicating they have visited that page. To prevent skipping, you'd add some code to query the visit tracking table to make sure they have visited the previous page in the subject. If not, either show an error or maybe redirect them to their continue point. To add the continue button, you'd query that visit table for the highest page in the subject that they have visited. Then either send them to that page or the next page, depending on what you want. That made me think of something. What if I were to make a table for Math and then structure it with ID for the users ID and set it to Varchar without AI because its just grabbing the data from a different table. Another one saying latestPage. Then say you goto Page2 it will do this: $page="http://localhost/page2.php" $sql="UPDATE math SET id="$_SESSION['id']", latestPage="$page" where id='$id'"; mysql_query($sql); Just a quick example. Basically each page I would just change $page to the page its on. Then if you exit and come back to continue it'll do this require_once('connect.php'); $id=$_SESSION['id']; $result3 = mysql_query("SELECT * FROM math where id='$id'"); while($row3 = mysql_fetch_array($result3)) { $latestPage=$row3['latestPage']; Then the link to continue would be simply like this: href="<?php echo $latestPage?>" The only question I have is before it saves the page into the database could I make it check to see if their latest page was a certain link, and if it was to go on with the function. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/282327-session-to-database/#findComment-1450496 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.