Jump to content

Randomizing Array from Database


isimpledesign

Recommended Posts

Hi Guys

 

I was just wondering if their is a function to randomize an array pulled from database is it possible i know their is array_rand() but it doesnt seem to work for me can someone show me where i am going wrong or do i have to do it from the actual SELECT statemant i.e ORDER_RAND(); ?

 

Here is what my array prints out.

 


$user_list = get_users_by_specialism($specialism);

	print_r($user_list);

outputs.

Array ( [0] => 129 [1] => 46 [2] => 57 [3] => 109 [4] => 92 [5] => 137 [6] => 238 [7] => 101 [8] => 60 [9] => 90 [10] => 112 [11] => 133 [12] => 121 [13] => 220 [14] => 275 [15] => 278 ) 

 

I basically need to make this array output in a random order everytime not by ID incrementing.

 

Any help Please

 

Cheers.

Link to comment
Share on other sites

You want to use 'order by rand()' for this. There's no point in returning every row within the database, loop through and store in an array, and then randomly sort that.. to do something you could do with a simple order by statement in the query.

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.