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.

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.] => ) )

Archived

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.