Author Topic: Random pictures  (Read 229435 times)

0 Members and 1 Guest are viewing this topic.

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Random pictures
« Reply #30 on: January 08, 2006, 12:02:55 AM »
Hi Gexx, Hi Michael

where do I have to implement the following code?

Code: [Select]
$cat_in = array(2,7,8,11,12,15,16,18); //list of category ids // *** TO FILTER 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").") AND i.cat_id IN (".implode(", ", $cat_in).")
       ORDER BY RAND()
       LIMIT $num_new_images";

I show about 12 different random image. But very often the same pictures is shown twice. I have more then 600 images in the database. So the chance to display the same pictures twice should not very high.

Thanks for helping me.

Offline TIMT

  • Hero Member
  • *****
  • Posts: 505
    • View Profile
Re: Random pictures
« Reply #31 on: January 12, 2006, 12:03:55 AM »
Please, anybody here who can help me??

Thanks a lot!

Michael

  • Guest
Re: Random pictures
« Reply #32 on: January 14, 2006, 07:05:45 PM »
Hallo,

index.php

Code: [Select]
//------------------------------------
//------- Random Images --------------
//------------------------------------
$num_new_images = $config['image_cells'];
$cat_in = array(33,32,34,35,36,37,38,4); //list of category ids // *** TO FILTER 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.image_rating > 8.5 AND i.image_votes > 1 AND i.cat_id IN (".get_auth_cat_sql("auth_viewcat").") AND i.cat_id IN (".implode(", ",$cat_in).")
       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);

die in Klammern stehenden Zahlen entsprechend den eigenen Cat Id's, die angezeigft werden sollen, austauschen

$cat_in = array(33,32,34,35,36,37,38,4); //list of category ids // *** TO FILTER RANDOM IMAGES ***

hier wird die Mindestbewertung eingestellt, es werden nur Bilder angezeigt die mindestens 8,5 Punkte haben!
Den Wert entsprechend tauschen.

WHERE i.image_active = 1 AND c.cat_id = i.cat_id AND i.image_rating > 8.5 AND i.image_votes > 1 AND i.cat_id IN (".get_auth_cat_sql


Ich hoffe es hilft Dir weiter  :D

Offline glitzer

  • Full Member
  • ***
  • Posts: 204
    • View Profile
    • over 7000 E-Cards
Re: Random pictures
« Reply #33 on: February 05, 2006, 01:59:20 PM »
How can i put it in other html sites..perhaps in the lightbox.html?

Greez

Offline Brainwrek

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Random pictures
« Reply #34 on: July 05, 2006, 07:03:10 AM »
I absolutely love this mod!  Thanks to everyone who has worked to build and support it.

I have a seemingly simple question about how to include random images on details.php.  I already have it working on index.php and categories.php, but details.php is giving me trouble.  Here's the code I've pasted into details.php:
Code: [Select]
//------------------------------------
//------- Random Images --------------
//------------------------------------
$num_new_images = 10;
$cat_in = array(119,112); //list of category ids // *** TO FILTER 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").") AND i.cat_id IN (".implode(", ",$cat_in).")
       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=\"row1\">\n";
   }
   $random_images .= "<td width=\"".$imgtable_width."\">\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);
The problem is that the code randomizes all the photos and then displays the wrong primary image... {image}.  The random pics show up just perfectly, but the {image} is also randomized.

I'm a total PHP hack (very dangerous)  8O, and I've tried many things to fix it, but without any luck so far.

Any ideas how to make this mod compatible with details.php?

Offline unite

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Random pictures
« Reply #35 on: July 07, 2006, 08:12:03 AM »
I have a question, I installed this mod on my site and it works well. The only thing I noticed is the area where is says (random Image) does not look like the box above it where it says (new Images) its a little different in size. Did I miss something or is this how its supposed to be?

www.vistawallpapers.ws

Offline Brainwrek

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Random pictures
« Reply #36 on: July 08, 2006, 03:53:52 PM »
I have a question, I installed this mod on my site and it works well. The only thing I noticed is the area where is says (random Image) does not look like the box above it where it says (new Images) its a little different in size. Did I miss something or is this how its supposed to be?

www.vistawallpapers.ws
Your NEW IMAGES table looks like this:
Code: [Select]
   
<table width="100%" border="0" cellspacing="0" cellpadding="4">
<tr>
<td class="head1" valign="top">New images</td>
</tr>
</table>

Your RANDOM IMAGES is wedged between table tags, like this:
Code: [Select]
</td>
</tr>
</table>
Random Images
<table width="100%" border="0" cellpadding="3" cellspacing="1">
<tr class="imagerow1">
<td width="34%" valign="top">
Construct your RANDOM IMAGES table the same way you did the NEW IMAGES table and you'll be set.

=========
NOW... Can anyone help me with my question above?  I really need to display random images in display.php without randomizing the main image.  Please...  :)

Offline unite

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Random pictures
« Reply #37 on: July 08, 2006, 06:04:14 PM »
Ok I have tried everything to get this to work lol. I am not that great at coding can some one help me fix these tables

Offline Brainwrek

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Random pictures
« Reply #38 on: July 11, 2006, 02:39:12 AM »
Ok I have tried everything to get this to work lol. I am not that great at coding can some one help me fix these tables
Follow the KISS rule on this.  You're making it too hard.  :)  The *easiest* way to do what you want is simply edit your home.html template.  Insert something like this right after your New Images table in home.html:
Code: [Select]

<br />
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr>
    <td>   
       <table width="100%"  border="0" align="center" cellpadding="4" cellspacing="0">
        <tr>
          <td class="head1">Random Pictures</td>
        </tr>
       </table>
    </td>
  </tr>
  <tr>
    <td>
      <table width="100%"  border="0" cellspacing="0" cellpadding="4">
        <tr>
          <td>{random_images}</td>
        </tr>
        </table>
     </td>
    </tr>
</table>
You will have to tweak the padding and spacing and width settings to fit perfectly, but if you're trying to accomplish this by editing index.php, you're making it too hard.   :wink:

Offline Brainwrek

  • Newbie
  • *
  • Posts: 21
    • View Profile
Re: Random pictures
« Reply #39 on: July 11, 2006, 02:42:37 AM »
Can someone please help me figure out how to make this work in details.php?

See my post above.  I can't figure out how to randomize the pics without randomizing the main photo on the page.   :?

Thanks guys.

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Random pictures
« Reply #40 on: January 03, 2007, 08:15:55 PM »
I tried this mod but it gives me this error:

An unexpected error occured. Please try again later.

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/beta/public_html/includes/db_mysql.php on line 116

And as soon as I remove the code V@NO posted the error is gone. What could be the problem (I use 4Images 1.7.4)

Offline BartAfterDark

  • Hero Member
  • *****
  • Posts: 520
    • View Profile
Re: Random pictures
« Reply #41 on: January 03, 2007, 09:06:56 PM »
aha. The problem was
FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c

FROM (".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c)

( ) was missing :) Now I only got one problem, how can I get it on 2 rows ?

Offline unite

  • Newbie
  • *
  • Posts: 48
    • View Profile
Re: Random pictures
« Reply #42 on: February 13, 2007, 10:51:30 PM »
I just set up a new site using the latest code. www.militarywallpaper.us and I have a older site vistawallpapers.com

This code works great on vistawallpaper site but if you look at militarywallpaper.us you will see the (random image) box does not display Random Images like the box above it.

Here is the code on the Home.html
         <table width="450" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="head1">
                        <table width="100%" border="0" cellspacing="0" cellpadding="4">
                          <tr>
                           <td class="head1" valign="top">{lang_random_images}</td>
                          </tr>
                        </table>
                      </td>
                    </tr>
                     <tr>
                      <td class="head1">{random_images}</td>
                    </tr>
                     </table>
                  <br />
 Same code as on Vista site that works fine. I'm at a loss any help would be great.

Jacob

  • Guest
Re: Random pictures
« Reply #43 on: March 17, 2007, 03:31:34 PM »
Can somebody please update this hack to use on 4images 1.7.4??

Please........  :roll: :roll:

Ok did it :) Tested on v1.7.4
Insert this code (edited as above) instead of the one suggested by vano at page 1
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---------

To control no. of random images to display, insert this (as suggested by vano) on the top of above code:
Code: [Select]
$num_new_images = 12;You can change 12 to any no. of random images to display.

« Last Edit: March 18, 2007, 04:46:56 AM by Jacob »

Offline quartz

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Random pictures
« Reply #44 on: March 18, 2007, 03:21:15 PM »
thanks Jacob its works perfectly.