Author Topic: Random pictures  (Read 177206 times)

0 Members and 1 Guest are viewing this topic.

Offline zibko

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Random pictures
« Reply #105 on: October 10, 2008, 12:42:34 AM »
I have on my web page 4images in subdirectory /galerija . I wish, that on my main page (/index.php), where are news, text, ... will be shown one random picture from my galery. How can I do this?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Random pictures
« Reply #106 on: October 10, 2008, 03:19:50 AM »
Welcome to 4images forum.

Did you see the very first message in this topic?


Hi all
I'm using 4images 1.7.6
i've tried using V@no's code with details.php
it shows what i want which is great but when i click on the thumb it takes me to a totally different picture!
if i go to index & click on the thumbs in a different category it always take me to a different cat & different pic

Actually it takes you to the right picture, its just randomizes your details picture...

use this code instead:
//------------------------------------
//------- Random Images --------------
//------------------------------------
$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 c.cat_id = i.cat_id AND i.cat_id IN ("
.get_auth_cat_sql("auth_viewcat").")
        ORDER BY RAND()
        LIMIT 6"
;
// end new
$result $site_db->query($sql);
$num_rows $site_db->get_numrows($result);

if (!
$num_rows)  {
  
$random_images "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr><td>";
//  $random_images .= $lang['no_new_images'];
  
$random_images .= "</td></tr></table>";
}
else  {
  
$random_images "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  
$count 0;
  
$bgcounter 0;
  
$image_backup $site_template->val_cache['image'];
  while (
$image_row $site_db->fetch_array($result)){
    if (
$count == 0) {
      
$row_bg_number = ($bgcounter++ % == 0) ? 2;
      
$random_images .= "<tr>\n";
    }
    
$random_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

    
show_image($image_row);
    
$random_images .= $site_template->parse_template("malenki");
    
$random_images .= "\n</td>\n";
    
$count++;
    if (
$count == 6) {
      
$random_images .= "</tr>\n";
      
$count 0;
    }
  } 
// end while
  
$site_template->val_cache['image'] = $image_backup;
  unset(
$image_backup);

  if (
$count 0)  {
    
$leftover = ($config['image_cells'] - $count);
    if (
$leftover >= 1) {
      for (
$f 0$f $leftover$f++) {
        
$random_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
      }
      
$random_images .= "</tr>\n";
    }
  }
  
$random_images .= "</table>\n";
// end else


$site_template->register_vars("random_images"$random_images);
unset(
$random_images);

//----- End Random Images---------
« Last Edit: October 10, 2008, 03:30:49 AM by V@no »
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 metal_brain

  • Jr. Member
  • **
  • Posts: 90
  • For all the reasons we have to die
    • View Profile
Re: Random pictures
« Reply #107 on: October 12, 2008, 07:56:53 AM »
Thanks V@no
& hey welcome back to this forum
you are the one :)

Offline zibko

  • Pre-Newbie
  • Posts: 4
    • View Profile
Re: Random pictures
« Reply #108 on: October 16, 2008, 06:20:16 PM »
This not work @V@no

So, my problem is.

I have galery here: http://www.pgd-dvor.si/galerija/

I want that random picture also will be on main page (say on right site) here: http://www.pgd-dvor.si/

I hope you understand what i want.

Offline olrac

  • Newbie
  • *
  • Posts: 34
    • View Profile
    • My Family Website
Re: Random pictures
« Reply #109 on: October 18, 2008, 07:43:09 PM »
is there any possible that i can put 4 random images? thanks
Lying like stealing.

Offline crs

  • Jr. Member
  • **
  • Posts: 76
    • View Profile
Re: Random pictures
« Reply #110 on: October 26, 2008, 01:19:08 PM »
Hallo, anscheinend wird das Layout der Zufallsbilder von der .HTML Datei der neuen Bilder bezogen.

Ich möchte bei den Zufallsbildern aber nur den das Bild angezeigt bekommen, ohne Namen etc.
Wie kann ich also eine andere .html Datei für die Zufallsbilder verwenden oder was muss ich verändern?

Offline Boemmel

  • Newbie
  • *
  • Posts: 14
    • View Profile
Re: Random pictures
« Reply #111 on: November 02, 2008, 02:09:21 AM »
ich hätte auch ein anliegen .
Ich hätte gerne nur die "Neue Bilder" als Zufallsbild auf der index-Seite.

Was muss ich dafür ändern ?

Gruß
Chris

Offline metal_brain

  • Jr. Member
  • **
  • Posts: 90
  • For all the reasons we have to die
    • View Profile
Re: Random pictures
« Reply #112 on: November 05, 2008, 12:02:12 PM »
I'm using this code     LINK
with a freash clean copy of 4images 1.7.6
it's working fine but i'm noticed that rating stopped working!!!! when i remove the code it works!!!!
so please could u advise
note hat i add the code directly above the Print Out and i use it in details.php


Offline metal_brain

  • Jr. Member
  • **
  • Posts: 90
  • For all the reasons we have to die
    • View Profile
Re: Random pictures
« Reply #113 on: November 06, 2008, 02:06:11 PM »
I'm using this code     LINK
with a freash clean copy of 4images 1.7.6
it's working fine but i'm noticed that rating stopped working!!!! when i remove the code it works!!!!
so please could u advise
note hat i add the code directly above the Print Out and i use it in details.php


I have removed the code from details.php and i'm using  the code on page_header.php
the rating & votes are working fine but now another problem appeared on search

this is the error
Code: [Select]
Notice: Undefined variable: additional_sql in /hermes/web05/b1164/pow.txttv/htdocs/includes/page_header.php on line 427when i search the pager header file the line 427 is
Code: [Select]
$sql = "SELECT i.image_id, i.catso any ideas?
thanks

Note: the url is http://www.txttv.tv/search.php

Offline metal_brain

  • Jr. Member
  • **
  • Posts: 90
  • For all the reasons we have to die
    • View Profile
Re: Random pictures
« Reply #114 on: November 12, 2008, 10:11:14 AM »
I solved it  :D

the code is meant to be used with index.php /home page
i wanted to use it with page_header.php & i was getting errors on search page
so what i did i copied the code that is missing from index.php
& it's working like a charm

here's the code i'm using in pager_header.php before ?>

Thanks vano for ur code & help
Code: [Select]
//------------------------------------
//------- Random Images by v@no --------------
//------------------------------------


$imgtable_width = ceil(intval($config['image_table_width']) / $config['image_cells']);
if ((substr($config['image_table_width'], -1)) == "%") {
  $imgtable_width .= "%";
}

$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 c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY RAND()
        LIMIT 6";
// end new
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr><td>";
//  $random_images .= $lang['no_new_images'];
  $random_images .= "</td></tr></table>";
}
else  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  $image_backup = $site_template->val_cache['image'];
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $random_images .= "<tr>\n";
    }
    $random_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n";

    show_image($image_row);
    $random_images .= $site_template->parse_template("thumbnail_bit");
    $random_images .= "\n</td>\n";
    $count++;
    if ($count == 6) {
      $random_images .= "</tr>\n";
      $count = 0;
    }
  } // end while
  $site_template->val_cache['image'] = $image_backup;
  unset($image_backup);

  if ($count > 0)  {
    $leftover = ($config['image_cells'] - $count);
    if ($leftover >= 1) {
      for ($f = 0; $f < $leftover; $f++) {
        $random_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n";
      }
      $random_images .= "</tr>\n";
    }
  }
  $random_images .= "</table>\n";
} // end else


$site_template->register_vars("random_images", $random_images);
unset($random_images);

//----- End Random Images---------

Offline TaijovuNeji

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: Random pictures
« Reply #115 on: December 03, 2008, 11:16:21 PM »
How can I show the random images vertically? Like this:
IMAGE 1
IMAGE 2
IMAGE 3


Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Random pictures
« Reply #116 on: December 04, 2008, 01:09:19 AM »
Welcome to 4images forum.

Use <br />
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 TaijovuNeji

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: Random pictures
« Reply #117 on: December 04, 2008, 02:08:34 AM »
Thanks!  :D .. this is a great forum!  :mrgreen:

So.. i know about the <br /> .. but where should I put this tag in this code:

Code: [Select]
//------- Random Images --------------
//------------------------------------
$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 c.cat_id = i.cat_id AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").")
        ORDER BY RAND()
        LIMIT $num_new_images";
// end new
$result = $site_db->query($sql);
$num_rows = $site_db->get_numrows($result);

if (!$num_rows)  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\"><tr class=\"imagerow1\"><td>";
//  $random_images .= $lang['no_new_images'];
  $random_images .= "</td></tr></table>";
}
else  {
  $random_images = "<table width=\"".$config['image_table_width']."\" border=\"0\" cellpadding=\"".$config['image_table_cellpadding']."\" cellspacing=\"".$config['image_table_cellspacing']."\">";
  $count = 0;
  $bgcounter = 0;
  while ($image_row = $site_db->fetch_array($result)){
    if ($count == 0) {
      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
      $random_images .= "<tr class=\"imagerow".$row_bg_number."\">\n ";
    }
    $random_images .= "<td width=\"".$imgtable_width."\" valign=\"top\">\n ";

    show_image($image_row);
    $random_images .= $site_template->parse_template("thumbnail_bit");
    $random_images .= "\n</td>\n ";
    $count++;
    if ($count == $config['image_cells']) {
      $random_images .= "</tr>\n ";
      $count = 0;

    }
  } // end while

  if ($count > 0)  {
    $leftover = ($config['image_cells'] - $count);
    if ($leftover >= 1) {
      for ($f = 0; $f < $leftover; $f++) {
        $random_images .= "<td width=\"".$imgtable_width."\">\n&nbsp;\n</td>\n ";
      }
      $random_images .= "</tr>\n ";
    }
  }
  $random_images .= "</table>\n ";
} // end else


$site_template->register_vars("random_images", $random_images);
unset($random_images);

//----- End Random Images---------

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Random pictures
« Reply #118 on: December 04, 2008, 02:55:30 AM »
Oh, my bad, I thought this was another topic about random image on external site...

In that code replace
Code: [Select]
    if ($count == $config['image_cells']) {
with:
Code: [Select]
    if ($count == 1) {
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 TaijovuNeji

  • Pre-Newbie
  • Posts: 8
    • View Profile
Re: Random pictures
« Reply #119 on: December 04, 2008, 03:15:32 AM »
I read the other topic about the <br /> .. but this command is used after this: "echo" and this script don't have "echo" O.o ..

But thanks man .. worked perfectly here what you talked to me.. you are master in php  :D

 

Post your comments here