Jump to content

Getting an array populated by a database to shuffle?


Recommended Posts

I'm trying to get an array that I've populated using a database to shuffle so that I can use it to ouput a random question. Here's my code:

 

<?php
mysql_connect("server", "user", "password") or die(mysql_error());
echo "Connected to MySQL<br/>";
mysql_select_db("database") or die(mysql_error());
echo "Connected to Database";
$result = mysql_query('SELECT * FROM table') or exit(mysql_error());
while ($row = mysql_fetch_assoc($result)){
	$array[] = $row;
}
shuffle($array);
print_r($array);
?>

 

This doesn't seem to shuffle it at all...

 

Any help is greatly appreciated.

Link to comment
Share on other sites

I was using the print_r to show the entire array. This is what I get when I print it out... I think the problem happens when I'm tryinto put it into an array, but I can't find any solutions.

 

Array ( [0] => Array ( [Question 1.] => [Question 2.] => [Question 3.] => [Question 4.] => [Question 5.] => ) )

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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