php - How to randomize images from albums -


this question has answer here:

i'm trying make image gallery. on index file want show albums images, see; http://www.robcnossen.nl/

i want randomize images inside these albums sorts of errors like:

warning: rand() expects parameter 1 long, string given in.

my code is;

foreach ($albums $album) { ?><div><h2><?php echo'<a href="view_album.php?album_id=', $album['id'],'">',$album['name'], '</a>';?>       </h2><?php            echo'<a href="view_album.php?album_id=', $album["id"],'"><img src="uploads/thumbs/', $album["id"], '/', $album["imagename"],'" title="" /></a>';     ?></div><?php } 

the $album["imagename"] images inside albums , want randomize part. tried example:

rand($album["imagename"], 0) 

but gives error.

i tried shuffle;

foreach ($albums $album) { shuffle($album["imagename"]); ?><div><h2><?php echo'<a href="view_album.php?album_id=', $album['id'],'">',$album['name'], '</a>';?></h2><?php           echo'<a href="view_album.php?album_id=', $album["id"],'"><img src="uploads/thumbs/', $album["id"], '/', $album["imagename"],'" title="" /></a>';     ?></div><?php } 

but there errors.

can me this?

var_dump($albums); gives

array(2) {    [0]=> array(8) {        ["id"]=> string(1) "8"        ["timestamp"]=> string(10) "1373890251"        ["name"]=> string(7) "holland"        ["description"]=> string(19) "fantastische foto's"        ["count"]=> string(1) "2"        ["imagename"]=> string(38) "konica minolta digital camera_428.jpeg"        ["image"]=> string(2) "63"        ["ext"]=> string(0) ""    }     [1]=> array(8) {        ["id"]=> string(1) "9"        ["timestamp"]=> string(10) "1376914749"        ["name"]=> string(6) "belgie"        ["description"]=> string(11) "mooi belgie"        ["count"]=> string(1) "2"        ["imagename"]=> string(12) "pict0170.jpg"        ["image"]=> string(2) "66"        ["ext"]=> string(0) ""     }   } 

as result.

shuffle should work you, not if put inside foreach loop, example code. need shuffle before start loop. also, shuffle needs called array itself, not item of array:

shuffle($albums); foreach ($albums $album) {     ... } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -