Jump to content

Archived

This topic is now archived and is closed to further replies.

xyn

random URL Generator

Recommended Posts

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

Share this post


Link to post
Share on other sites
You could use a simple script like this...

[code]
<?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>" ;
}
?>
[/code]

Share this post


Link to post
Share on other sites

×

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.