Jump to content

[SOLVED] omg it's gotten so confusing!


kellz

Recommended Posts

hey.. I got myself into such a mess^^ All i wanted to do was make a random question in a drop menu thing and then place the questions in a random order into the drop menu with the answer to that question in a random place in the drop menu aswell, confused?.. it's such a messy script and it just...doesn't work! lol it's evil! beware :P

 

<?php
srand((float) microtime() * 10000000);
$Q1='The water is in the ';
$Q2='Open the ';
$Q3='A animal with four legs ';
$Q4='A person is a ';
$Q5='A cat chases ';
$Q=''; $S='';
$ANS = '';
$input = array("The water is in the ", "Open the ", "A animal with four legs", "A person is a ", "A cat chases ");
$rnd = array_rand($input, 2);
$Q=$input[$rnd[0]];
IF ($Q == $input[0]) $ANS = 'Sea';
IF ($Q == $input[1]) $ANS = 'Door';
IF ($Q == $input[2]) $ANS = 'Cat';
IF ($Q == $input[3]) $ANS = 'Human';
IF ($Q == $input[4]) $ANS = 'Mouse';
for ($i=0;$i < 6; $i++) {
$arr = array("blue", "green", "orange", "purple", "white", "red", "gray", "yellow", "pink");
$rand = array_rand($arr, 2);
$S.='<option>' . $arr[$rand[0]] . '</option> ';
}
$out = '';
$t = 0;
$p=0;
$pieces = explode(" ", $S);
for ($i = 0; $i < 5; $i++) { 
    $out .= $pieces[$i].'<br>'; 
    while ($p < 100 && $t == 0) {
        if (rand(5, 10)==6) {
            $out .= ' ' . $ANS.'<br> ';
		echo $out;
            $t = 1;
        }
    }
}

$menu = <<<HERE
<select>
    $out
</select>
HERE;
echo $menu;

?>

 

I was trying for like an hour and 30 minutes in my lunch break (im so anti-social) it's all PHP's fault!! I'm in my IT class now and I'm actually supposed to be doing work in excel but i hate it so much! lol ok he wont catch me *i hope*.

Link to comment
Share on other sites

<html>
<head></head>
<body>

<?php

$results = array (
    'Sea'   => 'The water is in the',
    'Door'  => 'Open the',
    'Cat'   => 'An animal with four legs',
    'Human' => 'A person is a',
    'Mouse' => 'A cat chases a'
);

$questions = $results;
shuffle($questions);
$q_select = $_POST['question'];

$answers = array_keys($results); 
shuffle($answers);
$a_select = $_POST['answer'];

echo "<form method=\"POST\">\n";

echo "Question: <select name=\"question\">\n";
foreach ($questions as $question) {
  $selected = ($q_select==$question) ? ' selected="selected"' : '';
  echo "  <option value=\"$question\"$selected>$question</option>/n";
}
echo "</select><br>\n";


echo "Answer: <select name=\"answer\">\n";
foreach ($answers as $answer) {
  $selected = ($a_select==$answer) ? ' selected="selected"' : '';
  echo "  <option value=\"$answer\"$selected>$answer</option>/n";
}
echo "</select><br><br>\n";
echo "<button type=\"submit\">Submit</button>\n";
echo "</form>\n";

if (!empty($q_select) && !empty($a_select)) {

  echo "Your response: \"$q_select $a_select\"<br><br>\n";

  if ($results[$a_select]==$q_select) {
    echo "Correct answer.";
  } else {
    echo "Wrong answer, try again.";
  }
}

?>

</body>
</html>

Link to comment
Share on other sites

OMG your so clever and I'm so jealous and it's so totally unfair! you made it like 1000 lines shorter! now i feel bad because it's like i had to get someone else to do something for me instead of me doing it, you didn't have to waste your time doing all that but yesh it was nice of you <3 although I would be happy with hints or tips and .. stuff^^

Link to comment
Share on other sites

Well, I had some difficulty trying to understand what you were trying to accomplish by looking at your code - I have no idea what the array of colors was for. So, I just wrote some code based upon your explanation.

 

Rather than explain the code line-by-line, let me know if you have any specific questions and I can respond.

Link to comment
Share on other sites

to revraz: don't LOL'd at me :'(

 

to the person that told me to click "topic solved": will you go through a million posts and tell everyone else to do it too? it's not exactly solved yet, I might have another question about this, who knows?^^

 

to mjdamato: sry, I even confused myself and I don't know why i have colors there, they got there themself.. I really can't remember..

 

to santa: i want an nintendo ds for xmas and an ipod (i will also accept money for these items instead).

Link to comment
Share on other sites

 

to the person that told me to click "topic solved": will you go through a million posts and tell everyone else to do it too? it's not exactly solved yet, I might have another question about this, who knows?^^

 

 

then you make a new thread about your new problem... the people who dont topic solve tend to not get help if they develop a rep of not helping everyone else.

Link to comment
Share on other sites

I wasn't, I was laughing at Burnside poking fun at you :)

 

Oh, and Santa doesn't give money.  I've been trying for years to get it out of him.

 

to revraz: don't LOL'd at me :'(

 

to santa: i want an nintendo ds for xmas and an ipod (i will also accept money for these items instead).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.