Jump to content



Recommended Posts


I have a html table of 4 rows and four columns and the table is poulated with a random array of 16 out of 20 possibilities. The data is Japanese Kanji characters. I also have little mp3's of the pronounciation of each character and the idea is that the user has to click the table cell that contains the Kanji character they think matches the sound they hear. When they get it correct, they will recieve a score of 1....then they will move onto the next sound out of the original 16, which they will have to match etc etc. When they get sick of this array of 16, they can go back and select a new test, which will repeat the process with a different random array of 16.

What I'm trying to is......Lets assume they get the first one correct.....or incorrect come to that. Now I need to play another sound from the same 16 for the user to match to a table cell. Is it possible to shuffle the array?

// Retrieve all the data from the table
$result = mysql_query("SELECT * FROM kanji.temp")
or die(mysql_error());

// store the record of the table into $row
$row = mysql_fetch_array( $result99 );

srand ();
$myarray = array("$row[cpd_id_0]","$row[cpd_id_1]","$row[cpd_id_2]",
$myarray = $myarray[rand(0,count($doo)-1)];

echo "$myarray";


When the page loads, the result of the echo "$myarray" might be say, 2.mp3 (cpd_id_1). That's great...but...how do I stay in the same page and 'replay' the above, so-to-speak, so that the user can randomly work their way through the entire 16 possibilities? I doesn't matter if, for example, cpd_id_2 gets called twice or even three times as long it is random.

Hope this is possible....or perhaps I'm looking at this wrong. I thought/think shuffle() could be the answer, but I don't know how to stay in the same page and 'shuffle' the array to get a new result. If it is possible, could the array shuffle be triggered by a button perhaps?

Thanks heaps,

Link to post
Share on other sites
Okay, thanks for that. I was pretty sure that this wasn't going to fly, but I wanted to make sure that my understanding of the manual was correct. Rather than use JavaScript I'll go for the page reload option as this will be the smoothest way to go.

Just as an aside.....doesn't ORDER BY rand() do the same as shuffle()? If so, what's the point of having both? If not, what's the difference in the end result?

Thanks for your help,
Link to post
Share on other sites
[!--quoteo(post=353360:date=Mar 10 2006, 03:59 AM:name=realjumper)--][div class=\'quotetop\']QUOTE(realjumper @ Mar 10 2006, 03:59 AM) [snapback]353360[/snapback][/div][div class=\'quotemain\'][!--quotec--]

Just as an aside.....doesn't ORDER BY rand() do the same as shuffle()? If so, what's the point of having both? If not, what's the difference in the end result?


err... one is supported by MySql and the other one is php???

but than this is what pop-up in dreamweaver:

[!--coloro:#FF9900--][span style=\"color:#FF9900\"][!--/coloro--]rand([int min], int max)

shuffle(array array_arg)[!--colorc--][/span][!--/colorc--]

hmmm, i know what is array. but, don't really know how to use them much.
Link to post
Share on other sites
Shuffle really only makes sense if you're going to display more than one element from the array you're shuffling. If you're just returning one element, as it appears you are, then you are just picking a random element, not shuffling. Shuffling is like shuffling a deck of cards. You will never get two aces of hearts after shuffling a single deck.

If you want it to behave like a shuffle, i.e. you don't want to repeat anything, you'll have to come up with a solution for keeping persistent data (probably the data would be a full shuffled list and an index of where you currently are). You can store it with the user's session, put it in a cookie, or keep sending it through as form input.

To answer your aside, using ORDER BY RAND() on your query is exactly the same as using shuffle() on a PHP array. Doing it in MySQL is likely to perform better.
Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • 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.