Jump to content


Photo

random URL Generator


  • Please log in to reply
3 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 30 July 2006 - 08:57 PM

Hey,

I have an Image host, I wanted to have three Images,
Randomly shown on the homepage everytime the page
is refreshed. The problem is I don't know how to "randomly"
get an image ID from the SQL database...

I think I've seen this code somwhere but I can't remember.

Thanks
-Ash

#2 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 30 July 2006 - 09:09 PM

You could use a simple script like this...

<?php
mysql_connect ('localhost', 'username', 'password') ;
mysql_select_db ('database_name'); 
$number = 3 ;
$result = mysql_query ("SELECT * FROM images ORDER BY RAND() LIMIT $number"); 
while ($row = mysql_fetch_array($result)) 
{
echo "<a href=\"" . $row["link"] . "\">
<img src=\"" . $row["image"] . "\" border=0 alt=\"" . $row["text"] . "\">
</a>" ;
}
?>



#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 30 July 2006 - 09:19 PM

thx.

#4 maxic0

maxic0
  • Members
  • PipPipPip
  • Advanced Member
  • 70 posts

Posted 30 July 2006 - 09:22 PM

No problem, i hope it works ok for you.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users