Tutorial that Remembers Your Steps

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dyr
Forum Newbie
Posts: 22
Joined: Fri Mar 02, 2012 2:34 pm

Tutorial that Remembers Your Steps

Post by dyr »

Hi everyone, one of my friends would like to make an introductory tutorial on how to use their website. She wanted to make it kind of fun by having a 'character' be the tutorial guide. She has 5 characters she'd like the computer to randomly assign to new players. And since she doesn't really know PHP well, she's come to me. I don't know PHP well but I know it better than her, so here I am asking for a bit of help. Below is my logic.

1. Upon registering, a random number (1-5) is generated and inserted in to the user's table in the DB.

Code: Select all

$guide = rand(1, 5); 

mysql_query("INSERT INTO members (email, pass, pass_extra, user, pname, joindate, ip_address, activecode, guide) 
				VALUES ('$email', '$pass', '$salt', '$user', '$pname', NOW(), '$ip', '$key', '$guide')")
				or die ('cannot create a new member ' . mysql_error());
2. Upon logging in grab the $guide value

Code: Select all

$player = mysql_query("SELECT mid, user, pass, pass_extra, guide FROM members WHERE binary user = '$user'");
				$player = mysql_fetch_assoc($player);
Now here's where I'm stumped on what to use. Is it possible to use php for this next step, or is it easier in some other form of code?

3. Have a file included called guide.php where there is a list of text to choose from (below). And then somehow display that message.

Code: Select all

if($guide == 1){ echo 'Howdy! Here is step 1'; }
if($guide == 2){ echo 'Hello here is step 1'; }
if($guide == 3){ echo 'Hi here is step 1'; }
if($guide == 4){ echo 'Bonjour!  Here is step 1'; }
if($guide == 5){ echo 'Hola here is step 1'; }
However this is a tutorial, remember, so there needs to be a link they click on called 'Next' which displays different information. Guide 1, step 1: "Hi! Ready to begin?" user hits the next button Guide 1, step 2: "Okay, so click on this button" etc

How would I be able to incorporate that, and have the computer remember which step they were on?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Tutorial that Remembers Your Steps

Post by Celauran »

You might want to consider moving the text/instructions for the various guides into your database simply for ease of adding or removing guides down the road. In terms of remembering where each user left off, you can either set a flag in their account in the database, or you can use cookies. Constantly running UPDATE queries is expensive in terms of performance, but progress will be tracked by account rather than by browser, allowing you to pick up on one computer where you left off on another. Cookies are obviously browser-specific, but are much cheaper to write.
dyr
Forum Newbie
Posts: 22
Joined: Fri Mar 02, 2012 2:34 pm

Re: Tutorial that Remembers Your Steps

Post by dyr »

How would I go about using cookies to remember the guides? I haven't used them before.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Tutorial that Remembers Your Steps

Post by Celauran »

Post Reply