SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up having problem with random images

    hi

    i want dispaly images randomly .i have wriiten code for this. but its not working properly. i don't know what error in this.

    my database is look like

    in a single id i stored multiple image file names.

    id images
    10 bikes/b5.jpg,bikes/b5.jpg,bikes/b9.jp...
    11 bikes/b5.jpg,bikes/b5.jpg,bikes/b9.jp...

    -------------------

    <? mysql_connect("localhost", "root", "");
    mysql_select_db("img");
    $rangid=$_REQUEST['randid'];
    $sql="select * from newimg where imgid='$randid'";
    $res=mysql_query($sql);

    $row=mysql_fetch_array($res);

    $image=$row['images'];
    $tmp=explode(",",$image);
    foreach($tmp as $value)
    {
    //echo $value."<br>";
    srand((float) microtime() * 10000000);
    $tmp1=array_rand($value,1);
    echo $value[$tmp1[0]];
    }?>

  2. #2
    SitePoint Member Zombie's Avatar
    Join Date
    Jul 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just use the order by rand()

    Code:
    $sql="SELECT * from newimg ORDER BY RAND()";
    	$return = array();
    	while ($row = mysql_fetch_array($sql))
    		$return[] = array(
    			$image=$row['images'];
    		);
    
    return $return;
    Untested but should work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •