12-27-2007, 04:57 AM
|
#7 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
There is really no reason to put it in a class, objects are for reusable data and that isn't reusable. Something like this would be using a class for what its meat for.
pquiz.php
PHP Code:
<?php //I will only do one question for time reaons
// Get me mah classes! include 'class.php';
// Call up the Class, give vars user input (answers), then run them through the appropriate functions of the class.
$zaQuizone = new zlQuiz(); $zaQuizone->input = $_POST['questionone']; $zaQuizone->question = "What is the best language?"; $zaQuizone->answer = 'php'; $zaQuizone->success = '<font color="#009900">CORRECT</font><br /><hr /><br />'; $zaQuizone->failure = '<font color="#CC0000">INCORRECT</font><br />'; $zaQuizone->num = 1; $zaQuizone->question();
?>
class.php
PHP Code:
<? class zlQuiz { public $question; public $answer; public $success; public $failure; public $input; public $num;
// Question one function question() { echo "<b>Question #$num:</b> $this->question?<br /><br /><i>Your answer: $this->input <br /><br />";
if ($this->input == $this->answer) { echo $success; } else { echo $failure . "Correct Answer: $this->answer<br /><hr /><br />"; } } } ?>
Now you can make any amount of questions with any content without changing the class file.
Last edited by Village Idiot : 12-27-2007 at 05:28 AM.
|
|
|
|