Word Matching Application

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 "

\r\n";
===3D

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

===3D
echo "\r\n";
===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--

Re: Word Matching Application

am 06.01.2011 03:34:24 von Daniel Brown

On Wed, Jan 5, 2011 at 21:23, Ron Piggott
wrote:
>
> I only know how to do one array at a time, using FOREACH, like this:
>
> ===3D
> echo "

\r\n";
> ===3D

You could either swap that out for a simple `for` loop or add in
an array_combine() call and sort like so:

foreach ($new_array_name as $word =3D> $explanation)

--=20

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: Word Matching Application

am 06.01.2011 03:45:26 von ron.piggott

This works very well. Thank you for your assistance Dan. Ron


The Verse of the Day
“Encouragement from God’s Word”
http://www.TheVerseOfTheDay.info

-----Original Message-----
From: Daniel Brown
Sent: Wednesday, January 05, 2011 9:34 PM
To: Ron Piggott
Cc: php-db@lists.php.net ; Mike Stowe
Subject: Re: [PHP-DB] Word Matching Application

On Wed, Jan 5, 2011 at 21:23, Ron Piggott
wrote:
>
> I only know how to do one array at a time, using FOREACH, like this:
>
> ===
> echo "

\r\n";
> ===

You could either swap that out for a simple `for` loop or add in
an array_combine() call and sort like so:

foreach ($new_array_name as $word => $explanation)

--

Network Infrastructure Manager
Documentation, Webmaster Teams
http://www.php.net/


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php