4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: Horvath on May 09, 2009, 04:08:34 PM

Title: Random Image on different page
Post by: Horvath on May 09, 2009, 04:08:34 PM
Hello all, First off, I lovethis image gallery, Great job.

I am having a issue trying to get a randon image to show up on a seperate page.


I read some about random.php, but most was in a lauguange I cant read. Any one give me tips in English, I would be so greatfull.

Thank Eric
Title: Re: Random Image on different page
Post by: Nicky on May 09, 2009, 04:17:13 PM
hello and welcome to the 4images forum

here is one of them: [Mod] Random image / Zufallsbild (http://www.4homepages.de/forum/index.php?topic=1020.0)

but your file can't be index.html it should be index.php .. BUT you can use javascript to use it in index.html.. here the direct link how to use it: http://www.4homepages.de/forum/index.php?topic=1020.msg126303#msg126303

Title: Re: Random Image on different page
Post by: Horvath on May 09, 2009, 04:18:25 PM
Thanks I will check that out,

Thank you for the fast reply ! ! !

EDIT: I am not sure what to put at:  define('ROOT_PATH'  and     define('SCRIPT_URL'   

Could you give an example?
Title: Re: Random Image on different page
Post by: 4ella on May 09, 2009, 04:31:01 PM
Happy to know that too , I am the same case as Horvath , will want to put it on html principal page  ..
Title: Re: Random Image on different page
Post by: Horvath on May 09, 2009, 04:44:22 PM
I got it to work, just use this code as your random.php and edit you part to where your image gallery is
Code: [Select]
<?php
define
('ROOT_PATH''./');
define('SCRIPT_URL''http://gallery.rammstein-europe.com/');
include(
ROOT_PATH.'config.php');
include(
ROOT_PATH.'includes/db_mysql.php');
include(
ROOT_PATH.'includes/constants.php');

$site_db = new Db($db_host$db_user$db_password$db_name);
function 
is_remote($file_name) {
  return (
preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i'$file_name)) ? 0;
}

$sql "SELECT COUNT(*) as total_images
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b 
        WHERE a.image_active=1 
        AND a.cat_id = b.cat_id 
        AND b.auth_viewcat="
.AUTH_ALL.
        AND b.auth_viewimage="
.AUTH_ALL."
        "
;
$row $site_db->query_firstrow($sql);
$total_images $row['total_images'];

mt_srand((double)microtime() * 1000000);
$number = ($total_images 1) ? mt_rand(0$total_images 1) : 0;

$sql "SELECT a.image_id, a.cat_id, a.image_name, a.image_active, a.image_media_file, a.image_comments 
        FROM "
.IMAGES_TABLE." a, ".CATEGORIES_TABLE." b 
        WHERE a.image_active=1 
        AND a.cat_id = b.cat_id 
        AND b.auth_viewcat="
.AUTH_ALL.
        AND b.auth_viewimage="
.AUTH_ALL.
        LIMIT 
$number, 1";
$row $site_db->query_firstrow($sql);
$image_id $row['image_id'];
$cat_id $row['cat_id'];
$image_name $row['image_name'];
$image_comments $row['image_comments'];
$full_src = (is_remote($row['image_media_file'])) ? $row['image_media_file'] : SCRIPT_URL.ROOT_PATH.MEDIA_DIR."/".$cat_id."/".$row['image_media_file'];

print(
"
document.write('<a href=\""
.SCRIPT_URL."details.php?image_id=$image_id\"><img src=\"".$full_src."\" border=\"1\" alt=\"$image_name\"></a>');
"
);
?>


Then edit this and place it where you want your image to be displayed
Code: [Select]
<SCRIPT language='JavaScript'  src='http://gallery.rammstein-europe.com/random.php'></SCRIPT>
Also replace replace MEDIA_DIR with THUMB_DIR if you want the thumbnail to be displayed instead
Title: Re: Random Image on different page
Post by: 4ella on May 10, 2009, 12:08:06 AM
works perfect -:) thanks a lot Daniel
Title: Re: Random Image on different page
Post by: Nicky on May 10, 2009, 12:02:46 PM
hi guys,

sorry for delay, i'm rightnow in belgrade and looking 1time on day for news.

glad that it worked for you!