I am working on a word matching application.  Specifically the user will match 
a word with it’s definition.  I have made some progress since my last post for 
help (2 or 3 days ago).

I need help knowing how to alternate between displaying the word and it’s 

echo "<p>\r\n";

echo "<span class=\"bible_match_up_left\">\r\n";

    echo "WORD\r\n";

echo "</span>\r\n";

echo "<span class=\"bible_match_up_right\">\r\n";

    echo "EXPLANATION\r\n";

echo "</span>\r\n";

echo "</p>\r\n";

I only know how to do one array at a time, using FOREACH, like this:

echo "<ul>\r\n";

    foreach($match_words as $word) {
        echo "<li>" . $word . "</li>\r\n";

echo "</ul>\r\n";

How do I do both the word and explanation at once?

The following is how I query the database for the words / explanations and 
create and shuffle the arrays:

$query = "
SELECT `reference` , `word` , `explanation` 
FROM `Bible_dictionary` 
WHERE `live` =1

#create array from mySQL query

$words = array();
$explanations = array();

while ( $i <= $records_found ) {
    $reference = mysql_result($words_match_up_result,($i -1),"reference");
    $words[$reference] = stripslashes( mysql_result($words_match_up_result,($i 
-1),"word") );
    $explanations[$reference] = stripslashes( 
mysql_result($words_match_up_result,($i -1),"explanation") );


#shuffle from PHP web site
function custom_shuffle($my_array = array()) {
  $copy = array();
  while (count($my_array)) {
    // takes a rand array elements by its key
    $element = array_rand($my_array);
    // assign the array and its value to an another array
    $copy[$element] = $my_array[$element];
    //delete the element from source array
  return $copy;

$match_words = custom_shuffle($words);
$match_explanations = custom_shuffle($explanations);

$reference is not in sequential order.  $reference is the auto_increment value 
of the `Bible_dictionary`  table.  It’s significance is for scoring how many 
the user got right.


Reply via email to