Word Matching Application
am 06.01.2011 03:23:57 von ron.piggott------=_NextPart_000_0068_01CBAD1E.DCA201A0
Content-Type: text/plain;
charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
I am working on a word matching application. Specifically the user will =
match a word with itâ=99s 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â=99s explanation:
===3D
echo "
\r\n";
echo "\r\n";
echo "WORD\r\n";
echo "\r\n";
echo "\r\n";
echo "EXPLANATION\r\n";
echo "\r\n";
echo "
===3D
I only know how to do one array at a time, using FOREACH, like this:
===3D
echo "
- \r\n";
- " . $word . " \r\n";
foreach($match_words as $word) {
echo "
}
echo "
===3D
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:
===3D
$query =3D "
SELECT `reference` , `word` , `explanation`=20
FROM `Bible_dictionary`=20
WHERE `live` =3D1
ORDER BY RAND( )=20
LIMIT 5
";
$words_match_up_result=3Dmysql_query($query);
$records_found=3Dmysql_numrows($words_match_up_result);
#create array from mySQL query
$words =3D array();
$explanations =3D array();
$i=3D1;
while ( $i <=3D $records_found ) {
=20
$reference =3D mysql_result($words_match_up_result,($i =
-1),"reference");
$words[$reference] =3D stripslashes( =
mysql_result($words_match_up_result,($i -1),"word") );
$explanations[$reference] =3D stripslashes( =
mysql_result($words_match_up_result,($i -1),"explanation") );
++$i;
}
#shuffle from PHP web site
function custom_shuffle($my_array =3D array()) {
$copy =3D array();
while (count($my_array)) {
// takes a rand array elements by its key
$element =3D array_rand($my_array);
// assign the array and its value to an another array
$copy[$element] =3D $my_array[$element];
//delete the element from source array
unset($my_array[$element]);
}
return $copy;
}
$match_words =3D custom_shuffle($words);
$match_explanations =3D custom_shuffle($explanations);
===3D
$reference is not in sequential order. $reference is the auto_increment =
value of the `Bible_dictionary` table. Itâ=99s significance is =
for scoring how many the user got right.
Ron
------=_NextPart_000_0068_01CBAD1E.DCA201A0--