Jump to content

Array and Sticky problems


illadelphiakid

Recommended Posts

The code here is suppose to allow the user to match up a word ($word) with a list of definitions ($word_defs).  I can't get the list of definitions to stick.  When the user does make a guess it shows that he is always correct.  How can i fix these problems?

 

Outside entry code:

<?php
require_once "include/session.php";
require_once "include/word_defs.php";

$word = array_keys($word_defs); 
$word_defs = array_unique(array_values($word_defs));

$params = (object) $_REQUEST;
$session = new Session();

if (isset($params->guess)) {
  $word = $params->word;
  if ( $params->word == $word_defs[$term] ) {
    $response = "correct"; 
  } else {
    $response = "incorrect"; 
  }
  $choices->word_def[$params->word_def] = "selected";
} else {
  $word = $word[ rand( 0, count($word)-1 ) ];
}
?>

 

Body code:

 

word: <?php echo $word ?>


<form action="?" method="get">
definition: 
<select name="word_defs">
<?php foreach ($word_defs as $word_def): ?>
<option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option>
<?php endforeach ?>
</select>

<input type="submit" name="guess" value="Guess" />

<input type="hidden" name="word" value="<?php echo $word?>" />
</form>

<h3><?php echo $response ?></h3>

Link to comment
Share on other sites

The code here is suppose to allow the user to match up a word ($word) with a list of definitions ($word_defs).  I can't get the list of definitions to stick.  When the user does make a guess it shows that he is always correct.  How can i fix these problems?

 

Outside entry code:

<?php
require_once "include/session.php";
require_once "include/word_defs.php";

$word = array_keys($word_defs); 
$word_defs = array_unique(array_values($word_defs));

$params = (object) $_REQUEST;
$session = new Session();

if (isset($params->guess)) {
  $word = $params->word;
  if ( $params->word == $word_defs[$word] ) {
    $response = "correct"; 
  } else {
    $response = "incorrect"; 
  }
  $choices->word_def[$params->word_def] = "selected";
} else {
  $word = $word[ rand( 0, count($word)-1 ) ];
}
?>

 

Body code:

 

word: <?php echo $word ?>


<form action="?" method="get">
definition: 
<select name="word_defs">
<?php foreach ($word_defs as $word_def): ?>
<option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option>
<?php endforeach ?>
</select>

<input type="submit" name="guess" value="Guess" />

<input type="hidden" name="word" value="<?php echo $word?>" />
</form>

<h3><?php echo $response ?></h3>

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.