need help with this code
Posted: Fri Dec 12, 2008 9:47 pm
Hi again,
I hope I'm on the right track with this, and just missing something small.
I'm trying to create for my game a piece of code that checks the players education history, and then verify that 1. They didn't already take the class in question, and 2. Make sure they are not already enrolled in another class. If they meet both those requirements it will then enroll them in the class the chose.
What I have so far, it checks both requirements fine but I can't seem to get the final step to work. For testing I was just trying to get it to display the welcome message, but it doesn't display. It's just blank, so I think the else is in the wrong spot, or I have coded this all wrong.
I was trying to use a 'while' to check all the rows to make sure the player hasn't already taken the class, or enrolled in any other classes. The way I was coding worked fine, until the player passes all the requirements and ready to enroll, then nothing happens.
Here is the code where the checks and then final else after.
I hope I'm on the right track with this, and just missing something small.
I'm trying to create for my game a piece of code that checks the players education history, and then verify that 1. They didn't already take the class in question, and 2. Make sure they are not already enrolled in another class. If they meet both those requirements it will then enroll them in the class the chose.
What I have so far, it checks both requirements fine but I can't seem to get the final step to work. For testing I was just trying to get it to display the welcome message, but it doesn't display. It's just blank, so I think the else is in the wrong spot, or I have coded this all wrong.
I was trying to use a 'while' to check all the rows to make sure the player hasn't already taken the class, or enrolled in any other classes. The way I was coding worked fine, until the player passes all the requirements and ready to enroll, then nothing happens.
Here is the code where the checks and then final else after.
Code: Select all
$educationhistory = $db->execute("SELECT `classes_taken`, `player_id`, `days_left` FROM `education` WHERE `player_id`=?", array($player->id));
while ($educationhistory1 = $educationhistory->fetchrow())
{
if ($educationhistory1['classes_taken'] == $classid)
{
echo "You've already taken this class, apparently you didn't learn much";
break;
}
//check to verify not currently taking a class
else if ($educationhistory1['days_left'] > 0)
{
echo "Sorry you are currently already enrolled in a class<br>";
echo "Do you really think you're fooling anyone, you won't pass that one either";
echo "<a href=\"home.php\">home</a>";
break;
}
else
{
//player meets requirements update gold and enroll in class
echo "Thank You and Welcome<br>";
echo "<a href=\"home.php\">Home</a>";
}
}