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 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] 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. 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. Link to comment https://forums.phpfreaks.com/topic/16049-random-url-generator/#findComment-66114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.