Hey everyone,
We have an image module on our site: www.stonybrookmsa.com
But I need one that can randlomly choose one from a specific folder...because we have several ads we want to display. Anyone know how to do this?
- Farooq
- Teb answered »MenuTree Mystery« 05. Jul
- dks answered »include a file« 05. Jul
- dks answered ».764 -> 1.1.1, Can't add new blocks« 05. Jul
- craigh posted »PostCalendar 5.5.0RC1 needs testers and translators« 05. Jul
- bartl answered »Upgrading 1.0.2 --> 1.1.1« 05. Jul
- Charlie-otb answered »SafeHTML output filter and youtube« 05. Jul
- dl7und answered »Adding an "About Us" page« 05. Jul
Login
Random Image Generator...H-E-L-P!!!
-
-
- Rank: Freshman
- Registered: 31.05.03
- last visit: 21.11.08
- Posts: 31
I used the core block "Core/PHP".
My photo album script from smartor.
Code
$query = "SELECT * FROM nuke_phpbb_album";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
$start = "1";
$random = mt_rand($start, $numrows);
echo "<table align=\"center\" cellspacing=\"2\" border=\"0\"/><tr/><td align=\"center\"/>";
echo "<a href=\"http://www.sgwutan.com/modules.php?op=modload&name=PNphpBB2&file=album\"/><img src=\"index.php?name=PNphpBB2&file=album_thumbnail&pic_id=$random\"/></a/>";
echo "</table/>"; -
- Rank: Helper
- Registered: 07.02.03
- last visit: 12.06.08
- Posts: 226
You might want to take a look at the MultiImage module at:
http://noc.postnuke.com/projects/multiimage/
Allows you to have a random image block. -
- Rank: Helper
- Registered: 06.10.03
- last visit: 08.11.06
- Posts: 316
You could streamline that code a bit as well:
Code
$query = "SELECT * FROM nuke_phpbb_album ORDER BY RAND(MD5(NOW))) LIMIT 1";
$result = mysql_query($query);
$picrow = mysql_fetch_assoc($result);
$picid = $picrow['id']; //I don't know what the column name is so you would need to insert that here instead of 'id'
echo "<table align=\"center\" cellspacing=\"2\" border=\"0\"/><tr/><td align=\"center\"/>";
echo "<a href=\"http://www.sgwutan.com/modules.php?op=modload&name=PNphpBB2&file=album\"/><img src=\"index.php?name=PNphpBB2&file=album_thumbnail&pic_id=$picid\"/></a/>";
echo "</table/>";
This allows the mysql server to do the work of finding a random row. Not sure if it is really more or less effecient, just a different way of doing it. -
- Rank: Freshman
- Registered: 11.02.04
- last visit: 13.01.05
- Posts: 9
Hi,
Is it possible to create a "Recent Picture" block for Smartor's album with something like what you have here for "random block"? Can anyone please post code for it here? Your help will be greatly appreciated.
TIA
- Moderated by :
- Support
