Author Topic: Random image: any ideas???  (Read 16302 times)

0 Members and 1 Guest are viewing this topic.

Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Random image: any ideas???
« on: August 21, 2005, 09:30:25 PM »
Hi,

How can I add the user name in the Random image??

This is the code that I used:

Code: [Select]
<?php
define
('ROOT_PATH''./');
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;
}

$num_images 5;

$sql "SELECT a.image_id, a.image_date, a.cat_id, a.image_name, a.image_active, a.image_thumb_file
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."
ORDER BY a.image_date DESC
LIMIT 
$num_images";
$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
$image_id $row['image_id'];
$cat_id $row['cat_id'];
#$image_name = $row['image_name'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];


echo 
"<center><table><tr><td width=120 align=center><a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><br/><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br></td><td class=main_td valign=top><b>$image_name</b></td></td></table></center>\n";
}
?>

I try to add this code

Code: [Select]
LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)

under this

Code: [Select]
FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." b

but it doesn't work

any ideas

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #1 on: August 21, 2005, 09:44:04 PM »
Quote

but it doesn't work


Specifics please.

Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #2 on: August 21, 2005, 10:39:51 PM »
Thanks TheOracle for your reply

The error:

Fatal error: Call to undefined function: get_user_table_field()

I want to add the user name on this mod, the code shows only this
Code: [Select]
$sql = "SELECT a.image_id, a.image_date, a.cat_id, a.image_name, a.image_active, a.image_thumb_file

and I add this on the end of it

Code: [Select]
a.cat_name".get_user_table_field(", u.", "user_name")."

then I add this code

Code: [Select]
LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)

under this

Code: [Select]
FROM ".IMAGES_TABLE." a, ".CATEGORIES_TABLE." B

but it doesn't work

all I want is like this:


image name: google
Added by: AnGeL ========>> I want to add this to the Random image that's all

simply like this

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #3 on: August 21, 2005, 10:46:56 PM »
Quote

I want to add this to the Random image that's all


Well, in that case, I can't say I hate this idea. It's a good one I might add. ;)

Let me test this from my end and, if anyone else doesn't post the results before I do, I will keep this thread updated.

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #4 on: August 21, 2005, 10:51:09 PM »
Ok, first ;

change :

Quote

<?php
define('ROOT_PATH', './');
include(ROOT_PATH.'config.php');
include(ROOT_PATH.'includes/db_mysql.php');
include(ROOT_PATH.'includes/constants.php');


to :

Code: [Select]

<?php

define
('GET_CACHES'1);
define('ROOT_PATH''./');
define('GET_USER_ONLINE'1);
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();


Test this out and tell me your results.

Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #5 on: August 21, 2005, 11:07:55 PM »
Fatal error: Cannot redeclare is_remote()

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #6 on: August 21, 2005, 11:11:59 PM »
You don't need this part from your file :

Quote

function is_remote($file_name) {
return (preg_match('#^https?\\:\\/\\/[a-z0-9\-]+\.([a-z0-9\-]+\.)?[a-z]+#i', $file_name)) ? 1 : 0;
}


Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #7 on: August 21, 2005, 11:27:58 PM »
DB Error: Bad SQL Query: SELECT a.image_id, a.image_date, a.cat_id, a.image_name, a.image_active, a.image_thumb_file, a.cat_name, u.user_name FROM 4images_images a, 4images_categories b LEFT JOIN 4images_users u ON (u.user_id = i.user_id) WHERE a.image_active=1 AND a.cat_id = b.cat_id AND b.auth_viewcat=0 AND b.auth_viewimage=0 ORDER BY a.image_date DESC LIMIT 5
Unknown column 'a.cat_name' in 'field list'

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #8 on: August 21, 2005, 11:50:06 PM »
Replace :

Quote

$sql = "SELECT a.image_id, a.image_date, a.cat_id, a.image_name, a.image_active, a.image_thumb_file
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."
ORDER BY a.image_date DESC
LIMIT $num_images";
$result = $site_db->query($sql);


with :

Code: [Select]

$additional_sql = "";
if (!empty($additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}

$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name")."
        FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
        WHERE i.image_active = 1 AND i.cat_id = $cat_id AND c.cat_id = i.cat_id
        ORDER BY ".$config['image_order']." ".$config['image_sort']."
        LIMIT 1";
$result = $site_db->query($sql);


Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #9 on: August 22, 2005, 12:18:17 AM »
Now I have a blank page

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #10 on: August 22, 2005, 12:26:29 AM »
Quote

echo "<center><table><tr><td width=120 align=center><a href=\"".ROOT_PATH."details.php?image_id=$image_id\"><br/><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br></td><td class=main_td valign=top><b>$image_name</b></td></td></table></center>\n";


This part is wrong. The details.php path is not pointing correctly. Also, the string should be echoed but registered

like this :

Code: [Select]

$user_table_tracking = "";

$user_table_tracking .= "<center><table width=\"120\" cellpadding=\"0\" cellspacing=\"0\"><tr class=\"head2\"><td width=\"120\" align=\"center\" class=\"row2\"><a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id'])."\"><br/><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br></td><td class=\"main_td\" valign=\"top\"><b>".$row['image_name']."</b></td></td></table></center>\n";

$site_template->register_vars(array(
"user_table_tracking" => $user_table_tracking
));

unset ($user_table_tracking);


Then, use : {user_table_tracking} in your home / cats templates. It should work.

I'm not quite the pro with the remote image utility but this should do. ;)

Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #11 on: August 22, 2005, 12:59:42 AM »
It still blank and I used {user_table_tracking} in the home.html and it not showing any thing

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #12 on: August 22, 2005, 01:06:47 AM »
Then, post all the file I corrected for you and I will see - in one peace - what's might be wrong.

Offline |!^ AnGeL ^!|

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: Random image: any ideas???
« Reply #13 on: August 22, 2005, 02:39:19 AM »
Code: [Select]
<?php

define
('GET_CACHES'1);
define('ROOT_PATH''./');
define('GET_USER_ONLINE'1);
include(
ROOT_PATH.'global.php');
require(
ROOT_PATH.'includes/sessions.php');
$user_access get_permission();

$site_db = new Db($db_host$db_user$db_password$db_name);

$num_images 5;

$additional_sql "";
if (!empty(
$additional_image_fields)) {
  foreach ($additional_image_fields as $key => $val) {
    $additional_sql .= ", i.".$key;
  }
}

$sql "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.""user_name")."
        FROM "
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
        LEFT JOIN "
.USERS_TABLE." u ON (".get_user_table_field("u.""user_id")." = i.user_id)
        WHERE i.image_active = 1 AND i.cat_id = 
$cat_id AND c.cat_id = i.cat_id
        ORDER BY "
.$config['image_order']." ".$config['image_sort']."
        LIMIT 1"
;
$result $site_db->query($sql);

while (
$row $site_db->fetch_array($result)){
$image_id $row['image_id'];
$cat_id $row['cat_id'];
#$image_name = $row['image_name'];
$thumb_src = (is_remote($row['image_thumb_file'])) ? $row['image_thumb_file'] : ROOT_PATH.THUMB_DIR."/".$cat_id."/".$row['image_thumb_file'];


$user_table_tracking "";

$user_table_tracking .= "<center><table width=\"120\" cellpadding=\"0\" cellspacing=\"0\"><tr class=\"head2\"><td width=\"120\" align=\"center\" class=\"row2\"><a href=\"".$site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$image_row['image_id'])."\"><br/><img src=\"".$thumb_src."\" border=\"0\" alt=\"$image_name\"></a><br></td><td class=\"main_td\" valign=\"top\"><b>".$row['image_name']."</b></td></td></table></center>\n";

$site_template->register_vars(array(
"user_table_tracking" => $user_table_tracking
));

unset (
$user_table_tracking);
}
?>

TheOracle

  • Guest
Re: Random image: any ideas???
« Reply #14 on: August 22, 2005, 04:07:20 AM »
After testing this, I have the impression that this routine cannot be executed outside the category page. However, there's a MOD about this which you can customize. Perhaps your request would be more adaptive with the addition. ;)

Which is from this topic :

http://www.4homepages.de/forum/index.php?topic=4259.0

;)