Word Matching Application

------=_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=E2=80=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=E2=80=99s explanation:

=3D=3D=3D
echo "<p>\r\n";

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

echo "WORD\r\n";

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

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

echo "EXPLANATION\r\n";

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

echo "</p>\r\n";
=3D=3D=3D

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

=3D=3D=3D
echo "<ul>\r\n";

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

echo "</ul>\r\n";
=3D=3D=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=3D=3D
$query =3D "
SELECT `reference` , `word` , `explanation`
FROM `Bible_dictionary`
WHERE `live` =3D1
ORDER BY RAND( )
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 ) {

$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=3D=3D

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

Ron
------=_NextPart_000_0068_01CBAD1E.DCA201A0--
ron.piggott [ Do, 06 Januar 2011 03:23 ] [ ID #2052648 ]

Re: Word Matching Application

On Wed, Jan 5, 2011 at 21:23, Ron Piggott
<ron.piggott [at] actsministries.org> wrote:
>
> I only know how to do one array at a time, using FOREACH, like this:
>
> =3D=3D=3D
> echo "<ul>\r\n";
>
> =A0 =A0foreach($match_words as $word) {
> =A0 =A0 =A0 =A0echo "<li>" . $word . "</li>\r\n";
> =A0 =A0}
>
> echo "</ul>\r\n";
> =3D=3D=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)

--
</Daniel P. Brown>
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
Daniel Brown [ Do, 06 Januar 2011 03:34 ] [ ID #2052649 ]

Re: Word Matching Application

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 [at] lists.php.net ; Mike Stowe
Subject: Re: [PHP-DB] Word Matching Application

On Wed, Jan 5, 2011 at 21:23, Ron Piggott
<ron.piggott [at] actsministries.org> wrote:
>
> 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";
> ===

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)

--
</Daniel P. Brown>
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
ron.piggott [ Do, 06 Januar 2011 03:45 ] [ ID #2052650 ]
PHP » gmane.comp.php.database » Word Matching Application

Vorheriges Thema: using PDO vs mysql extension
Nächstes Thema: Two forms on one page - THE ANSWER