im trying to randomze a set a results from the database,
this is the bases of the array:
array (size=30)
0 => string '1' (length=1)
1 => string 'jordan' (length=6)
2 => string 'chris' (length=5)
3 => string '1' (length=1)
4 => string '1' (length=1)
5 => string 'card1, card2, card3, card4, card5, card6, card7, card8' (length=54)
6 => string 'card16, card20, card30, card40, card50, card60, card70, card80' (length=62)
7 => string '' (length=0)
8 => string '' (length=0)
9 => string '' (length=0)
10 => string '' (length=0)
11 => string '' (length=0)
12 => string '' (length=0)
13 => string '' (length=0)
14 => string '' (length=0)
15 => string '' (length=0)
16 => string '' (length=0)
17 => string '' (length=0)
18 => string '' (length=0)
19 => string '' (length=0)
20 => string '' (length=0)
21 => string '' (length=0)
22 => string '' (length=0)
23 => string '' (length=0)
24 => string '' (length=0)
25 => string '' (length=0)
26 => string '' (length=0)
27 => string '2013-11-21 04:23:19' (length=19)
28 => string '0' (length=1)
29 => string '0' (length=1)
im wanting to pull the data from array[5] and shuffle it/randomize it
while ($row = mysql_fetch_array($cards, MYSQL_NUM)) {
var_dump($row);
var_dump(array_rand($row[6], 2 ));
}
i've tried various things and now im just at the stage of getting confused even more than i did when i first started can someone help me out?
Explode your string first:
$cards = explode(",", $row[6]);
then, randomize, using shuffle
, and implode:
shuffle($cards);
$result = implode(",", $cards);
it should now be a shuffled list.
You can use the php function shuffle in order to randomize in array. Then you just have to pull the data you want to an array, shuffle it and then display it :)
Try this
function getR($ipt)
{
$pieces = explode(",", $ipt);
return $pieces[mt_rand(0,count($pieces)-1)];
}
while ($row = mysql_fetch_array($cards, MYSQL_NUM))
{
echo getR($row[5]);
}