xyn Posted July 30, 2006 Share Posted July 30, 2006 Hey,I have an Image host, I wanted to have three Images,Randomly shown on the homepage everytime the pageis 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 Quote Link to comment https://forums.phpfreaks.com/topic/16049-random-url-generator/ Share on other sites More sharing options...
maxic0 Posted July 30, 2006 Share Posted July 30, 2006 You could use a simple script like this...[code]<?phpmysql_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] Quote Link to comment https://forums.phpfreaks.com/topic/16049-random-url-generator/#findComment-66110 Share on other sites More sharing options...
xyn Posted July 30, 2006 Author Share Posted July 30, 2006 thx. Quote Link to comment https://forums.phpfreaks.com/topic/16049-random-url-generator/#findComment-66113 Share on other sites More sharing options...
maxic0 Posted July 30, 2006 Share Posted July 30, 2006 No problem, i hope it works ok for you. Quote Link to comment https://forums.phpfreaks.com/topic/16049-random-url-generator/#findComment-66114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.