Author Topic: Random Image  (Read 14591 times)

0 Members and 1 Guest are viewing this topic.

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« on: March 18, 2003, 02:38:50 AM »
I would like to re-display the random image from my gallery on other pages within a: my forum and b: an independant website, is this possible or am I clutching at straws?

Mike

Offline Neo1

  • Full Member
  • ***
  • Posts: 202
    • View Profile
    • http://www.terradreams.de/
Random Image
« Reply #1 on: March 18, 2003, 03:20:29 AM »

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #2 on: March 31, 2003, 03:09:36 AM »
Quote from: Neo1
Look here http://www.4homepages.de/forum/viewtopic.php?t=1020&start=0
I hope this is what you need.


Need help with this!

 I have downloaded the code:
**/

// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', './4images/');

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)) ? 1 : 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_thumb_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'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br>\n";
echo "<b>$image_name</b><br>\n";
echo "Comments: $image_comments<br>\n";
?>

But wherever I try to implement it only so far produces errors or displays the code on the page with no image, what am I missing?

Here is where I want random image to display, somewhere within homepage. http://www.hovedogs.co.uk

Offline Neo1

  • Full Member
  • ***
  • Posts: 202
    • View Profile
    • http://www.terradreams.de/
Random Image
« Reply #3 on: March 31, 2003, 01:12:14 PM »
First of all.......you can only incluse this to a PHP-Page. So if your page is a htm or html .......rename it to *.php and than include.


Quote
// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', './4images/');


And this is not right. Try this:
Code: [Select]
define('ROOT_PATH', '../Gallery/');

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #4 on: April 01, 2003, 03:38:03 AM »
Sorry Jan I must be really dim :cry: I cannot get this to work, I have changed html file to php as you said but all I get displayed is the code i entered in the first place!!!!!!!!

If you can help me where i am going wrong I would apreciate it.

Here is the link where I added the code to test:

http://www.rockysracers.co.uk/Random_image.php

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Random Image
« Reply #5 on: April 01, 2003, 04:04:30 AM »
Quote from: swifter_uk
Here is the link where I added the code to test:

http://www.rockysracers.co.uk/Random_image.php

I think u forgot add <?php at the beginning of the file.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #6 on: April 01, 2003, 07:02:35 PM »
Thanks v@no,

Tried that too, but still cannot make it work, I must be too dumb!! :cry:

Tried loading to another server that I know definately runs php.

http://www.hovedogs.co.uk/Random_image.php but still no joy!!

Offline Neo1

  • Full Member
  • ***
  • Posts: 202
    • View Profile
    • http://www.terradreams.de/
Random Image
« Reply #7 on: April 01, 2003, 09:28:57 PM »
Please post the full code.

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #8 on: April 01, 2003, 10:42:19 PM »
Quote from: Neo1
Please post the full code.


here it is:

<?php
/**************************************************************************
 *                                                                        *
 *    4images - A Web Based Image Gallery Management System               *
 *    ----------------------------------------------------------------    *
 *                                                                        *
 *             File: random.php                                           *
 *        Copyright: (C) 2002 Jan Sorgalla                                *
 *            Email: jan@4homepages.de                                    *
 *              Web: http://www.4homepages.de                             *
 *    Scriptversion: 1.0 for 4images 1.6.1                                *
 *                                                                        *
 *    Never released without support from: Nicky (http://www.nicky.net)   *
 *                                                                        *
 **************************************************************************
 *                                                                        *
 *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 *    bedingungen (http://www.4homepages.de/4images/lizenz.php) für       *
 *    weitere Informationen.                                              *
 *    ---------------------------------------------------------------     *
 *    This script is NOT freeware! Please read the Copyright Notice       *
 *    (http://www.4homepages.de/4images/lizenz_e.php) for further         *
 *    information.                                                        *
 *                                                                        *
 *************************************************************************/


// http://www.hovegallery.co.uk/Gallery
define('ROOT_PATH', '../Gallery/');

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)) ? 1 : 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_thumb_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'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];

echo "<a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br>\n";
echo "<b>$image_name</b><br>\n";
echo "Comments: $image_comments<br>\n";
?>

Offline Neo1

  • Full Member
  • ***
  • Posts: 202
    • View Profile
    • http://www.terradreams.de/
Random Image
« Reply #9 on: April 01, 2003, 11:01:41 PM »
The code is ok. I have copy this to my folder and open it and it works fine:

http://www.terradreams.de/gallery/random1.php


Try to upload your Random_image.php (like it is) to your Gallery Folder and open it in your browser

http://www.hovedogs.co.uk/Gallery/Random_image.php

If it works, you can include it in every PHP-page on your site.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Random Image
« Reply #10 on: April 02, 2003, 12:33:20 AM »
the problem is in define('ROOT_PATH', '../Gallery/');
since u put your random.php file in root dir on your server, u must use just one dot: define('ROOT_PATH', './Gallery/');
two dots (../) means that one dir behind.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #11 on: April 02, 2003, 12:59:18 AM »
I think I understand now!!

Will let you know how I get on, thanks for all the help with this...very grateful :D

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #12 on: April 02, 2003, 01:27:41 AM »
One small question...

now I have it working how do I display this random image on the front of my forum, http://www.hovedogs.co.uk/Owners_Forum

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Random Image
« Reply #13 on: April 02, 2003, 01:44:27 AM »
then, use ../
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline swifter_uk

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
    • http://www.hovedogs.co.uk
Random Image
« Reply #14 on: April 02, 2003, 01:47:07 AM »
Sorry I am a total dunce with this. I need something more specific :cry: