View Full Version : random image code
Dini
May 25th, 2006, 18:07
Does anyone know a HTML or PHP code that can load a random image from a certain selection? (lets say 5 images). Please help, I'm looking for one myself right now
ardnat
May 25th, 2006, 18:31
i have see one wait let me look did you try hotscripts?
Dini
May 25th, 2006, 18:57
yes, but I found a few scripts and I just need a piece of code. Thanks :)
stuffradio
May 25th, 2006, 19:35
Hang on, I think I can do one with a database if you have access to one. Let me make it and I'll post it on here for everyone to see.
stuffradio
May 25th, 2006, 20:09
Ok, this was made using a mysql database, you can see what it looks like:
http://wuensche.ca/random/
here is the code for config.php:
<?php
mysql_connect("localhost", "username", "password");
mysql_select_db("mysql_database");
?>
index.php code:
<?php
require_once("config.php");
$random = mt_rand(1, 6);
$img = mysql_query("SELECT * FROM `images` WHERE id='$random'");
$img = mysql_fetch_array($img);
echo "<img src='$img[image]' alt='$img[name]'><br>";
?>
I just made it now, not perfect but you can tweak it :) You can download the .sql file at www.wuensche.ca/random/images.sql
Dini
May 25th, 2006, 21:43
This is great! Already used it, thanks!!!!
quivira
June 16th, 2006, 13:19
Not sure if this will help, but you can also use arrays and do sort of the same thing, using a random selector like mt_rand(); but it looks like you already used it.
Hope this helps anyone else.
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.