Author Topic: Random Image on different page  (Read 6142 times)

0 Members and 1 Guest are viewing this topic.

Offline Horvath

  • Newbie
  • *
  • Posts: 11
    • View Profile
Random Image on different page
« 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
« Last Edit: May 09, 2009, 06:41:30 PM by Horvath »

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Random Image on different page
« Reply #1 on: May 09, 2009, 04:17:13 PM »
hello and welcome to the 4images forum

here is one of them: [Mod] Random image / Zufallsbild

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

cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Horvath

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random Image on different page
« Reply #2 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?

Offline 4ella

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • http://www.dancersrecruit.com/pictures/
Re: Random Image on different page
« Reply #3 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  ..

http://www.dancersrecruit.com/pictures/
4IMAGES 1.7.6 version/default theme
Apache version   2.2.11 (Unix)
PHP version   5.2.9
MySQL version   5.0.75-community-log
Architecture   x86_64
Operating system   Linux

Offline Horvath

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random Image on different page
« Reply #4 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
« Last Edit: May 09, 2009, 05:07:15 PM by Horvath »

Offline 4ella

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • http://www.dancersrecruit.com/pictures/
Re: Random Image on different page
« Reply #5 on: May 10, 2009, 12:08:06 AM »
works perfect -:) thanks a lot Daniel

http://www.dancersrecruit.com/pictures/
4IMAGES 1.7.6 version/default theme
Apache version   2.2.11 (Unix)
PHP version   5.2.9
MySQL version   5.0.75-community-log
Architecture   x86_64
Operating system   Linux

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
Re: Random Image on different page
« Reply #6 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!
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi