Forum Activity

Forum feed

» see all | » latest posts

Random Image Generator...H-E-L-P!!!  Top

  • 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
  • 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/>";
  • 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.
  • 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.
  • 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

This list is based on the users active over the last 60 minutes.