4images Forum & Community

4images Modifications / Modifikationen => Mods & Plugins (Requests & Discussions) => Topic started by: ChrisTTian on January 17, 2003, 03:22:18 PM

Title: New Pics in Category
Post by: ChrisTTian on January 17, 2003, 03:22:18 PM
Hello

I would like to include a php file in my main page with the following content:

Quote
NEWEST PICS in the IMAGE GALLERY!!!

You can find new Pics in Catagory:

- .... (insert name here) (date)
- .... (insert name here) (date)
- ....


No pic should pop up here. Only the category name and the date of the last update should appear.

The category name should be clickable and lead to the category in the image gallery

It would be fine to adjust the time. Lets say I would like to know smething like "list those categories where there has been an upload in the last 3 days" or so.

As I am not very firm with php and sql could you please send me an example or create a mod for that.

I think this might be very useful especially for news pages. See my newspage on http://www.tt-owners.de/php/news/news.php . I display the last threads from phpBB forum on the left side at "Diskussionstreff" and I would like to add the last categories of the image gallery below or on the right side.

WHY?
Especially in news pages you are forced to provide all kind of information just in compressed summarised form to make some appetite for more browsing.

Praying for some helpful people wo initialise a tiny little mod for me and all others. I guess that shouldn't bee to hard. Maybe the random pic mod can be adjusted to my description?

Greetings
Christian
Title: Quick code....
Post by: SLL on January 17, 2003, 10:20:25 PM
It's not a real MOD, it's written right now, in five minutes... I hope you can do what you want out of it...
Code: [Select]
<?php

define
&#40;'ROOT_PATH', './'&#41;;
include&#40;ROOT_PATH.'global.php'&#41;;
require&#40;ROOT_PATH.'includes/sessions.php'&#41;;
$user_access get_permission&#40;&#41;;
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;;
$number_of_news 5;

$sql "SELECT i.image_name, i.image_date, c.cat_name, u.user_name
        FROM "
.IMAGES_TABLE." i, ".CATEGORIES_TABLE." c, ".USERS_TABLE." u
        WHERE i.image_active = 1 AND i.cat_id NOT IN &#40;
$cat_id_sql&#41; AND i.cat_id = c.cat_id AND i.user_id = u.user_id $cat_match_sql
        ORDER BY i.image_date DESC
        LIMIT 
$number_of_news";
$result $site_db->query&#40;$sql&#41;;
$new_images_list = array&#40;&#41;;
$i 1;
while &
#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123;
  
$new_images_list[$i&#93; = $row;
  
$i++;
&
#125;
$site_db->free_result&#40;&#41;;

for &#40;$i = 1; $i <= $number_of_news; $i++&#41; &#123;
  
if &#40;isset&#40;$new_images_list[$i&#93;&#41;&#41; &#123;

$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$new_images_list[$i&#93;['image_date'&#93;&#41;;
$news = &#40;"new image <b>" . $new_images_list[$i&#93;['image_name'&#93; . "</b> in the category <b>" . $new_images_list[$i&#93;['cat_name'&#93; . "</b> uploaded by <b>" . $new_images_list[$i&#93;['user_name'&#93; . "</b> on <b>" . $image_date . "</b><br>" &#41;;

echo $news;

  &
#125;
&#125;
?>


As a result of this I see:

new image Gala in the category Girlz uploaded by SLL on 17.01.2003 01:13
new image Natasha in the category Girlz uploaded by SLL on 17.01.2003 01:11
new image Boris in the category Boyz uploaded by SLL on 17.01.2003 00:59
new image Dmitry in the category Boyz uploaded by SLL on 17.01.2003 00:59
new image Sergey in the category Boyz uploaded by SLL on 17.01.2003 00:56

Jost edit your homepage and insert <?php include("this_filename.php"); ?> in the proper place. I hope this is what you wanted :wink:
Title: New Pics in Category
Post by: ChrisTTian on January 20, 2003, 11:49:31 AM
Wow  :!:

I didn't expect to have a ready file  8O

Thank you for this fast reply. The result really looks like what I expected. I will try it this evening. Many thanks!!!  :P

I will let you know if this is what I was looking for and post my news page as soon as it is included.

Christian
Title: New Pics in Category
Post by: ChrisTTian on January 20, 2003, 12:09:02 PM
Hello

I forgot one little thing. I hope you can help me:

Is there a way to modify the code that the follwing result will appear:

- New image(s) in category A on 01/18/2003
- New image(s) in category B on 01/16/2003

1) I would like to set a time span for the result like:

Code: [Select]
"Show me those categories where new images have been added the recent 7 days"

Not every image should be listed by name. The category is all I need :-).  Otherwise the list will grow too much and be too long for the news page. I would like to display only the category name as in my sample above.

2) If I click on the cateqory I should jump to the category in the image gallery.

May I ask you for another 5 min to write me the code please. Many thanks in advance!!!

Christian
Title: New Pics in Category
Post by: gti-the-sexy on January 20, 2003, 03:38:40 PM
thanx a lot SLL
but how could I link the image names??
Title: New Pics in Category
Post by: gti-the-sexy on January 20, 2003, 07:17:27 PM
help please for linking
Title: New Pics in Category
Post by: SLL on January 20, 2003, 11:24:27 PM
Quote from: ChrisTTian
May I ask you for another 5 min to write me the code please.

I don't have time to make this code clean, but at least it works... :)  feel free clean it up and modify (and post here)
Code: [Select]

<?php

define
&#40;'ROOT_PATH', './4images/'&#41;;
include&#40;ROOT_PATH.'global.php'&#41;;
require&#40;ROOT_PATH.'includes/sessions.php'&#41;;
$user_access get_permission&#40;&#41;;

$number_of_new_pics 15;
$days_to_be_new 1;

$new_cutoff time&#40;&#41; - 60 * 60 * 24 * $days_to_be_new;
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;;

$sql "SELECT MAX&#40;cat_id&#41; as max_id FROM ".CATEGORIES_TABLE;
$row $site_db->query_firstrow&#40;$sql&#41;;
$cat_max_id = &#40;!empty&#40;$row['max_id'&#93;&#41;&#41; ? $row['max_id'&#93; &#58; 0;

for &#40;$i = 0; $i <= $cat_max_id; $i++&#41;&#123;

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name
          FROM "
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i";
   
$result $site_db->query&#40;$sql&#41;;
   
$row $site_db->fetch_array&#40;$result&#41;;
    
$images_in_category $site_db->get_numrows&#40;$result&#41;;

   
$category_name = &#40;$row['cat_name'&#93;&#41;;
   
$category_id = &#40;$row['cat_id'&#93;&#41;;
    
$category_link = &#40;"<a href=\"" . ROOT_PATH . "categories.php?cat_id=" . $category_id . "\">"&#41;;

if &#40;$images_in_category&#41; &#123; echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>"; &#125;

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name
          FROM "
.IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
          LEFT JOIN "
.USERS_TABLE." u ON u.user_id = i.user_id
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i
          ORDER BY i.image_date DESC
          LIMIT 
$number_of_new_pics";

   
$result $site_db->query&#40;$sql&#41;;
  
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123;
   
$image_name = &#40;$row['image_name'&#93;&#41;;
   
$image_id = &#40;$row['image_id'&#93;&#41;;
   
$category_name = &#40;$row['cat_name'&#93;&#41;;
   
$user_name = &#40;$row['user_name'&#93;&#41;;
   
$media_path = &#40;$row['image_media_file'&#93;&#41;;
   
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;;
   
$allnew_link = &#40;"<a href=\"" . ROOT_PATH . "search.php?search_new_images=1" . "\">"&#41;;

   
echo "<ul><b>$image_name</b> uploaded by <b>$user_name</b>&nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>";
  &
#125;
&#125;
   
echo "$allnew_link Show all new images? </a>";
?>

Title: New Pics in Category
Post by: gti-the-sexy on January 21, 2003, 12:26:44 AM
Warning: Failed opening './4images/global.php' for inclusion (include_path='.:/sys/php-4.2.3/lib/php') in /vhosts/mydomainname.com/http/4images/test.php on line 4
Title: New Pics in Category
Post by: gti-the-sexy on January 21, 2003, 12:31:04 AM
I put test.php to my root directory and coming test.php like this:

Show all new images?

that's it. no links and no image lists :) only this sentence appear

the html source of this page:
-----------------------
Show all new images? </a>
-----------------------

did u test it SLL :)
Title: New Pics in Category
Post by: SLL on January 21, 2003, 08:56:25 AM
Sure I did check it! Don't try to make me more stupid, that I am  :wink:
You can also check yourself http://www.dalnet.ru/get_new_pics.php It's in Russian, but in this case it doesn't matter...

Check path in your file!
Code: [Select]
define('ROOT_PATH', './4images/');
I've also added number of categories check into the code above.
Title: New Pics in Category
Post by: gti-the-sexy on January 21, 2003, 09:24:44 PM
path is right

if I change the right path then an error gives

Warning: Failed opening './mngpicturesX/global.php' for inclusion (include_path='.:/sys/php-4.2.3/lib/php') in /vhosts/mydomain.com/http/mngpicturesX/test.php on line 4

I could't find the mistake :((

my script gives me only
--------------
"Show all new images?"
---------------
Title: New Pics in Category
Post by: gti-the-sexy on January 21, 2003, 11:48:41 PM
the first code running exactly without any problems, but this code can't give the links of images

could you add image links to this code SLL please?

Code: [Select]

<?php 

define
&#40;'ROOT_PATH', './'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 
$number_of_news 5

$sql "SELECT i.image_name, i.image_date, c.cat_name, u.user_name 
        FROM "
.IMAGES_TABLE." i, ".CATEGORIES_TABLE." c, ".USERS_TABLE." u 
        WHERE i.image_active = 1 AND i.cat_id NOT IN &#40;
$cat_id_sql&#41; AND i.cat_id = c.cat_id AND i.user_id = u.user_id $cat_match_sql 
        ORDER BY i.image_date DESC 
        LIMIT 
$number_of_news"
$result $site_db->query&#40;$sql&#41;; 
$new_images_list = array&#40;&#41;; 
$i 1
while &
#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
  
$new_images_list[$i&#93; = $row; 
  
$i++; 
&
#125; 
$site_db->free_result&#40;&#41;; 

for &#40;$i = 1; $i <= $number_of_news; $i++&#41; &#123; 
  
if &#40;isset&#40;$new_images_list[$i&#93;&#41;&#41; &#123; 

$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$new_images_list[$i&#93;['image_date'&#93;&#41;; 
$news = &#40;"new image <b>" . $new_images_list[$i&#93;['image_name'&#93; . "</b> in the category <b>" . $new_images_list[$i&#93;['cat_name'&#93; . "</b> uploaded by <b>" . $new_images_list[$i&#93;['user_name'&#93; . "</b> on <b>" . $image_date . "</b><br>" &#41;; 

echo $news

  &
#125; 
&#125; 
?>

Title: New Pics in Category
Post by: SLL on January 22, 2003, 12:23:02 AM
Quote from: gti-the-sexy
path is right
if I change the right path then an error gives Warning: Failed opening './mngpicturesX/global.php' for inclusion

no, it's not right :)

let's say, the full path for the of you site homepage is /vhosts/mydomain.com/http/index.html, and the path for 4images startpage is /vhosts/mydomain.com/http/mngpicturesX/index.php

put this script into the root directory of your site, not 4images root! (or include in your main index.html).

then the root path definition in this script should be
Code: [Select]
define('ROOT_PATH', './mngpicturesX/');

try harder  :wink:  as i said (and as you can see with the link to my site) it works....
Title: New Pics in Category
Post by: gti-the-sexy on January 22, 2003, 10:40:03 AM
I PUT THIS SCRIPT TO MY ROOT DIRECTORY which is /vhosts/mydomain.com/http/
AND CHANGED ROOT PATH DEFINITION

but only I see

"Show all new images?"

could't you add linking images in this code?

Code: [Select]

<?php 

define
&#40;'ROOT_PATH', './'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 
$number_of_news 5

$sql "SELECT i.image_name, i.image_date, c.cat_name, u.user_name 
        FROM "
.IMAGES_TABLE." i, ".CATEGORIES_TABLE." c, ".USERS_TABLE." u 
        WHERE i.image_active = 1 AND i.cat_id NOT IN &#40;
$cat_id_sql&#41; AND i.cat_id = c.cat_id AND i.user_id = u.user_id $cat_match_sql 
        ORDER BY i.image_date DESC 
        LIMIT 
$number_of_news"
$result $site_db->query&#40;$sql&#41;; 
$new_images_list = array&#40;&#41;; 
$i 1
while &
#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
  
$new_images_list[$i&#93; = $row; 
  
$i++; 
&
#125; 
$site_db->free_result&#40;&#41;; 

for &#40;$i = 1; $i <= $number_of_news; $i++&#41; &#123; 
  
if &#40;isset&#40;$new_images_list[$i&#93;&#41;&#41; &#123; 

$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$new_images_list[$i&#93;['image_date'&#93;&#41;; 
$news = &#40;"new image <b>" . $new_images_list[$i&#93;['image_name'&#93; . "</b> in the category <b>" . $new_images_list[$i&#93;['cat_name'&#93; . "</b> uploaded by <b>" . $new_images_list[$i&#93;['user_name'&#93; . "</b> on <b>" . $image_date . "</b><br>" &#41;; 

echo $news

  &
#125; 
&#125; 
?>



because this code runs exactly withour any problems
Title: New Pics in Category
Post by: ChrisTTian on January 22, 2003, 01:42:48 PM
Back to your last code ;-)

Hello again

I tried to adjust the file to my table names. My tables are called "4images_categories" and "4images_images". So I changed the code for the table names. But now I get a parse error in line 14. Why? This code is in line 14:

Code: [Select]
  $sql = "SELECT MAX(cat_id) as max_id FROM ".4images_categories;

What I didn't understand ist what the "." in front of the table name means. In the other code you write the table name in quotas (") and have a dot at the beginning and the end of the table name. Is there something wrong? Because for me it didn't work. Maybe a navive question of an amateur ;-)

Below you'll find the complete code with the replaced table names. Is ther anything else to change?

Greetings Christian

Code: [Select]
<?php 

define
&#40;'ROOT_PATH', './4images/'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 

$number_of_new_pics 15
$days_to_be_new 1

$new_cutoff time&#40;&#41; - 60 * 60 * 24 * $days_to_be_new; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 

   
$sql "SELECT MAX&#40;cat_id&#41; as max_id FROM ".4images_categories
   
$row $site_db->query_firstrow&#40;$sql&#41;; 
   
$cat_max_id = &#40;!empty&#40;$row['max_id'&#93;&#41;&#41; ? $row['max_id'&#93; &#58; 0; 

for &#40;$i = 0; $i <= $cat_max_id; $i++&#41;&#123; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name 
          FROM "
.4images_images." i,  ".4images_categories." c 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i"
   
$result $site_db->query&#40;$sql&#41;; 
   
$row $site_db->fetch_array&#40;$result&#41;; 
    
$images_in_category $site_db->get_numrows&#40;$result&#41;; 

   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$category_id = &#40;$row['cat_id'&#93;&#41;; 
    
$category_link = &#40;"<a href=\"" . ROOT_PATH . "categories.php?cat_id=" . $category_id . "\">"&#41;; 

if &#40;$images_in_category&#41; &#123; echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>"; &#125; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name 
          FROM "
.4images_images." i,  ".4images_categories." c 
          LEFT JOIN "
.4images_users." u ON u.user_id = i.user_id 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i 
          ORDER BY i.image_date DESC 
          LIMIT 
$number_of_new_pics"

   
$result $site_db->query&#40;$sql&#41;; 
  
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
   
$image_name = &#40;$row['image_name'&#93;&#41;; 
   
$image_id = &#40;$row['image_id'&#93;&#41;; 
   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$user_name = &#40;$row['user_name'&#93;&#41;; 
   
$media_path = &#40;$row['image_media_file'&#93;&#41;; 
   
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;; 
   
$allnew_link = &#40;"<a href=\"" . ROOT_PATH . "search.php?search_new_images=1" . "\">"&#41;; 

   
echo "<ul><b>$image_name</b> uploaded by <b>$user_name</b>&nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>"
  &
#125; 
&#125; 
   
echo "$allnew_link Show all new images? </a>"
?>
Title: New Pics in Category
Post by: V@no on January 22, 2003, 01:50:43 PM
I think u dont need to change anything, just use exact same code with .CATEGORIES_TABLE;
Title: New Pics in Category
Post by: ChrisTTian on January 22, 2003, 02:03:02 PM
I tried the same scrpt but now I get the following error:

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN phpbb_users u ON u.user_id = i.user_id WHERE i.image_active = 1 AND i.image_date >= 1043153567 AND c.cat_id = i.cat_id AND i.cat_id = 0 ORDER BY i.image_date DESC LIMIT 15
Unknown column 'u.user_name' in 'field list'

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN phpbb_users u ON u.user_id = i.user_id WHERE i.image_active = 1 AND i.image_date >= 1043153567 AND c.cat_id = i.cat_id AND i.cat_id = 1 ORDER BY i.image_date DESC LIMIT 15
Unknown column 'u.user_name' in 'field list'

DB Error: Bad SQL Query: SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name FROM 4images_images i, 4images_categories c LEFT JOIN phpbb_users u ON u.user_id = i.user_id WHERE i.image_active = 1 AND i.image_date >= 1043153567 AND c.cat_id = i.cat_id AND i.cat_id = 2 ORDER BY i.image_date DESC LIMIT 15
Unknown column 'u.user_name' in 'field list'
Show all new images?

So what is wrong now?  :roll:

Thank you again for your help
Title: New Pics in Category
Post by: ChrisTTian on January 22, 2003, 02:09:05 PM
I guess it is because I use 4images together with phpBB forum.

The table "phpbb_users" is in the same database as all other tables of 4images

Christian
Title: New Pics in Category
Post by: SLL on January 22, 2003, 03:04:51 PM
Quote from: ChrisTTian
I guess it is because I use 4images together with phpBB forum. The table "phpbb_users" is in the same database as all other tables of 4images

oh yesss... you almost right. i've spent few days trying to understand, why "random images" doesn't work together with "fetch phpbb stats"

the reason is that both of them using the same table names. http://www.4homepages.de/forum/viewtopic.php?t=1020&postdays=0&postorder=asc&start=135
the solution is: define table names directly in this script, using different names
Code: [Select]
define('PIC_CATEGORIES_TABLE', '4images_categories');
define('PIC_IMAGES_TABLE', '4images_images');
define('PIC_USERS_TABLE', '4images_images');


and add this PIC_ to the queries... this should help
Title: New Pics in Category
Post by: SLL on January 22, 2003, 03:08:54 PM
Quote from: gti-the-sexy
I PUT THIS SCRIPT TO MY ROOT DIRECTORY which is /vhosts/mydomain.com/http/ AND CHANGED ROOT PATH DEFINITION but only I see "Show all new images?"
could't you add linking images in this code?
Code: [Select]
define('ROOT_PATH', './');
because this code runs exactly withour any problems


hey hey! open your eyes!  :evil:
the root for you should be
Code: [Select]
define('ROOT_PATH', './mngpicturesX/');
and image links are there, btw...
Title: New Pics in Category
Post by: gti-the-sexy on January 22, 2003, 04:02:52 PM
Quote from: SLL
Quote from: ChrisTTian
I guess it is because I use 4images together with phpBB forum. The table "phpbb_users" is in the same database as all other tables of 4images

oh yesss... you almost right. i've spent few days trying to understand, why "random images" doesn't work together with "fetch phpbb stats"

the reason is that both of them using the same table names. http://www.4homepages.de/forum/viewtopic.php?t=1020&postdays=0&postorder=asc&start=135
the solution is: define table names directly in this script, using different names
Code: [Select]
define('PIC_CATEGORIES_TABLE', '4images_categories');
define('PIC_IMAGES_TABLE', '4images_images');
define('PIC_USERS_TABLE', '4images_images');


and add this PIC_ to the queries... this should help


I added PIC_ and defines but I got the same error which Christ. got
Title: New Pics in Category
Post by: ChrisTTian on January 22, 2003, 04:11:16 PM
Well I am finally getting closer  :wink:

On my test system only the user name is missing yet. Maybe the productive environment will solve my problem

Found 2 new images in category Sternfahrt    ...view category

PIC00025 uploaded by     ...view image
PIC00023 uploaded by     ...view image
Show all new images?


Maybe a little bug:

If $number_of_new_pics is been set to "1" and there has been no picture uploaded I get the following code and I can't click the link like mentioned in a thread before:

Show all new images?

It seems that the variable

Code: [Select]
$allnew_link

will be ignored because the html code shows only

Show all new images? </a>

with the missing http:.... string.

Can you include a "if...else question"

If there are new pics in the last x day show me:

Found 2 new images in category Sternfahrt    ...view category
PIC00025 uploaded by     ...view image
PIC00023 uploaded by     ...view image
Show all new images?


If there are no pics in the last days show me

There are no New pics. Klick here to surf the image gallery.

This should make the circle round if there were no new pics. I tried to add an "else" somewhere in your code but I couldn't figure out where to put it.


Below is the code with the included "define" lines and the added "PIC_" for people like me using phpBB and 4images together. I hope that the user name problem can be fixed.

Once again a big thank you to SSL  :!:  :!:  :!:
Christian

Code: [Select]
<?php 

define
&#40;'ROOT_PATH', './4images/'&#41;;
define&#40;'PIC_CATEGORIES_TABLE', '4images_categories'&#41;; 
define&#40;'PIC_IMAGES_TABLE', '4images_images'&#41;; 
define&#40;'PIC_USERS_TABLE', '4images_users'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 

$number_of_new_pics 1
$days_to_be_new 100

$new_cutoff time&#40;&#41; - 60 * 60 * 24 * $days_to_be_new; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 

   
$sql "SELECT MAX&#40;cat_id&#41; as max_id FROM ".PIC_CATEGORIES_TABLE
   
$row $site_db->query_firstrow&#40;$sql&#41;; 
   
$cat_max_id = &#40;!empty&#40;$row['max_id'&#93;&#41;&#41; ? $row['max_id'&#93; &#58; 0; 

for &#40;$i = 0; $i <= $cat_max_id; $i++&#41;&#123; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name 
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i"
   
$result $site_db->query&#40;$sql&#41;; 
   
$row $site_db->fetch_array&#40;$result&#41;; 
    
$images_in_category $site_db->get_numrows&#40;$result&#41;; 

   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$category_id = &#40;$row['cat_id'&#93;&#41;; 
    
$category_link = &#40;"<a href=\"" . ROOT_PATH . "categories.php?cat_id=" . $category_id . "\">"&#41;; 

if &#40;$images_in_category&#41; &#123; echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>"; &#125; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name 
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c 
          LEFT JOIN "
.PIC_USERS_TABLE." u ON u.user_id = i.user_id 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i 
          ORDER BY i.image_date DESC 
          LIMIT 
$number_of_new_pics"

   
$result $site_db->query&#40;$sql&#41;; 
  
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
   
$image_name = &#40;$row['image_name'&#93;&#41;; 
   
$image_id = &#40;$row['image_id'&#93;&#41;; 
   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$user_name = &#40;$row['user_name'&#93;&#41;; 
   
$media_path = &#40;$row['image_media_file'&#93;&#41;; 
   
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;; 
   
$allnew_link = &#40;"<a href=\"" . ROOT_PATH . "search.php?search_new_images=1" . "\">"&#41;; 

   
echo "<ul><b>$image_name</b> uploaded by <b>$user_name</b>&nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>"
  &
#125; 
&#125; 
   
echo "$allnew_link Show all new images? </a>"
?>
Title: New Pics in Category
Post by: gti-the-sexy on January 22, 2003, 08:13:28 PM
THANKSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS


SLL & CHRIST :)
Title: New Pics in Category
Post by: SLL on January 22, 2003, 10:29:20 PM
Quote from: ChrisTTian
On my test system only the user name is missing yet. Maybe the productive environment will solve my problem
Not exactly.. Since I have no phpBB integration, I can't check it myself, but I believe you should define phpBBusers (or whatever it's name is) as 'PIC_USERS_TABLE' and get user name out of it.

Quote from: ChrisTTian
If $number_of_new_pics is been set to "1" and there has been no picture uploaded
$number_of_new_pics variable stands for maximum number of pics found to show under the category info.
Get the code with all (I believe  :lol: ) corrections you asked for:
Code: [Select]
<?php
define
&#40;'ROOT_PATH', './4images/'&#41;;
define&#40;'PIC_CATEGORIES_TABLE', '4images_categories'&#41;;
define&#40;'PIC_IMAGES_TABLE', '4images_images'&#41;;
define&#40;'PIC_USERS_TABLE', '4images_users'&#41;;
include&#40;ROOT_PATH.'global.php'&#41;;
require&#40;ROOT_PATH.'includes/sessions.php'&#41;;
$user_access get_permission&#40;&#41;;

$number_of_new_pics 5;
$days_to_be_new 3;

$new_cutoff time&#40;&#41; - 60 * 60 * 24 * $days_to_be_new;
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;;

   
$sql "SELECT MAX&#40;cat_id&#41; as max_id FROM ".PIC_CATEGORIES_TABLE;
   
$row $site_db->query_firstrow&#40;$sql&#41;;
   
$cat_max_id = &#40;!empty&#40;$row['max_id'&#93;&#41;&#41; ? $row['max_id'&#93; &#58; 0;

$total_images_found 0;
for &
#40;$i = 0; $i <= $cat_max_id; $i++&#41;&#123;

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i";
   
$result $site_db->query&#40;$sql&#41;;
   
$row $site_db->fetch_array&#40;$result&#41;;
   
$images_in_category $site_db->get_numrows&#40;$result&#41;;
   
$total_images_found $total_images_found $images_in_category;

   
$category_name = &#40;$row['cat_name'&#93;&#41;;
   
$category_id = &#40;$row['cat_id'&#93;&#41;;
   
$category_link = &#40;"<a href=\"" . ROOT_PATH . "categories.php?cat_id=" . $category_id . "\">"&#41;;

if &#40;$images_in_category&#41; &#123;
echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>";&#125;

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.user_name
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c
          LEFT JOIN "
.PIC_USERS_TABLE." u ON u.user_id = i.user_id
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i
          ORDER BY i.image_date DESC
          LIMIT 
$number_of_new_pics";

   
$result $site_db->query&#40;$sql&#41;;
  
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123;
   
$image_name = &#40;$row['image_name'&#93;&#41;;
   
$image_id = &#40;$row['image_id'&#93;&#41;;
   
$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$row['image_date'&#93;&#41;;
   
$category_name = &#40;$row['cat_name'&#93;&#41;;
   
$user_name = &#40;$row['user_name'&#93;&#41;;
   
$media_path = &#40;$row['image_media_file'&#93;&#41;;
   
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;;

   
echo "<ul><b>$image_name</b> uploaded by <b>$user_name</b> at <b>$image_date</b>&nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>";
  &
#125;
 
&#125;
if &#40;!$total_images_found&#41; &#123;
   
$gallery_link = &#40;"<a href=\"" . ROOT_PATH . "index.php" . "\">"&#41;;
echo "No new images found within last $days_to_be_new days. Click $gallery_link here</a> to surf the gallery...<br>";
   &
#125; else &#123;
  
$allnew_link = &#40;"<a href=\"" . ROOT_PATH . "search.php?search_new_images=1" . "\">"&#41;;
   
echo "$allnew_link Would you like to see all new images? </a>";
&#125;
?>
Title: New Pics in Category
Post by: _Keith_ on January 23, 2003, 01:54:53 AM
I want this but I would like it to use with IPF (IBF) Forums

heres my site right now. I kind of want to add this into the portal. I have a idea on how to do it and I am gonna play with your code a bit to see what I come up with but any help to put this in would be greatly appreciated.
Title: New Pics in Category
Post by: ChrisTTian on January 23, 2003, 11:02:09 AM
Hi SLL it finally works!!!

aaaaand: I get the username as well  :!:

There is a tiny little difference between the table "users" in 4images and the table "users" in phpBB:

In 4images the filed is called "user_name" but in phpBB the filed is called "username"

So when i changed as you wrote above the code

Code: [Select]
define('PIC_USERS_TABLE', '4images_users');

to the phpbb table

Code: [Select]
define('PIC_USERS_TABLE', 'phpbb_users');

I got the correct error:

Unknown column 'u.user_name' in 'field list'

Of course there is now no field "user_name" in phpBB. But if I change the $sql statement from "u.user_name" to "u.username" it works correct.

So here is the complete code for people who have included 4images and phpbb:

It is up to you SLL to move this code to the final section of the forum because ist is your great work!!! I will send you the link to my news page as soon as I have included it. Hopefully this evening ;-)

Greetings and 1000 Thank you to Russia ;-)

Code: [Select]
<?php 
define
&#40;'ROOT_PATH', './4images/'&#41;; 
define&#40;'PIC_CATEGORIES_TABLE', '4images_categories'&#41;; 
define&#40;'PIC_IMAGES_TABLE', '4images_images'&#41;; 
define&#40;'PIC_USERS_TABLE', 'phpbb_users'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 

$number_of_new_pics 5
$days_to_be_new 30

$new_cutoff time&#40;&#41; - 60 * 60 * 24 * $days_to_be_new; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 

   
$sql "SELECT MAX&#40;cat_id&#41; as max_id FROM ".PIC_CATEGORIES_TABLE
   
$row $site_db->query_firstrow&#40;$sql&#41;; 
   
$cat_max_id = &#40;!empty&#40;$row['max_id'&#93;&#41;&#41; ? $row['max_id'&#93; &#58; 0; 

$total_images_found 0
for &
#40;$i = 0; $i <= $cat_max_id; $i++&#41;&#123; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name 
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i"
   
$result $site_db->query&#40;$sql&#41;; 
   
$row $site_db->fetch_array&#40;$result&#41;; 
   
$images_in_category $site_db->get_numrows&#40;$result&#41;; 
   
$total_images_found $total_images_found $images_in_category

   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$category_id = &#40;$row['cat_id'&#93;&#41;; 
   
$category_link = &#40;"<a href=\"" . ROOT_PATH . "categories.php?cat_id=" . $category_id . "\">"&#41;; 

if &#40;$images_in_category&#41; &#123; 
   
echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>";&#125; 

  
$sql "SELECT i.image_id, i.cat_id, i.image_active, i.image_name, i.image_date, c.cat_name, u.username 
          FROM "
.PIC_IMAGES_TABLE." i,  ".PIC_CATEGORIES_TABLE." c 
          LEFT JOIN "
.PIC_USERS_TABLE." u ON u.user_id = i.user_id 
          WHERE i.image_active = 1 AND i.image_date >= 
$new_cutoff AND c.cat_id = i.cat_id AND i.cat_id = $i 
          ORDER BY i.image_date DESC 
          LIMIT 
$number_of_new_pics"

   
$result $site_db->query&#40;$sql&#41;; 
  
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
   
$image_name = &#40;$row['image_name'&#93;&#41;; 
   
$image_id = &#40;$row['image_id'&#93;&#41;; 
   
$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$row['image_date'&#93;&#41;; 
   
$category_name = &#40;$row['cat_name'&#93;&#41;; 
   
$user_name = &#40;$row['user_name'&#93;&#41;; 
   
$media_path = &#40;$row['image_media_file'&#93;&#41;; 
   
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;; 

   
echo "<ul><b>$image_name</b> uploaded by <b>$user_name</b> at <b>$image_date</b>&nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>"
  &
#125; 
&#125; 
if &#40;!$total_images_found&#41; &#123; 
   
$gallery_link = &#40;"<a href=\"" . ROOT_PATH . "index.php" . "\">"&#41;; 
   
echo "No new images found within last $days_to_be_new days. Click $gallery_link here</a> to surf the gallery...<br>"
   &
#125; else &#123; 
  
$allnew_link = &#40;"<a href=\"" . ROOT_PATH . "search.php?search_new_images=1" . "\">"&#41;; 
   
echo "$allnew_link Would you like to see all new images? </a>"
   &
#125; 
?>
Title: New Pics in Category
Post by: SLL on January 23, 2003, 11:59:43 AM
Quote from: _Keith_
I want this but I would like it to use with IPF (IBF) Forums

I believe you don't have to change anything in this code to make it work with your forum. Just make right table definitions.
Title: New Pics in Category
Post by: SLL on January 23, 2003, 12:05:55 PM
Quote from: ChrisTTian
It is up to you SLL to move this code to the final section of the forum because ist is your great work!!!
I don't think it's a MOD, we're not modifying anything in 4images  :)
In order to publish it, at least the output of this script shouldn't be so ugly  :wink:  
What about this? http://www.dalnet.ru/get_new_pics.php
Title: New Pics in Category
Post by: ChrisTTian on January 23, 2003, 12:50:47 PM
SLL

this looks really great! Was ist hard to make?

Btw: Didn't know that Russia has so many beautyful women ;-)

Just too bad that i cant read kyrillic and don't understand russian. What do you use your image gallery for?
 
Greetings
Christian

P.S.: The link to my web site is http://www.tt-owners.de. A Page about a car from Aud called "Audi TT"
Title: New Pics in Category
Post by: SLL on January 23, 2003, 01:26:09 PM
Quote from: ChrisTTian
Was ist hard to make?

5 more minutes :)  http://sll.blood.ru/for_chris.zip
Quote from: ChrisTTian
Btw: Didn't know that Russia has so many beautyful women ;-)  Just too bad that i cant read kyrillic and don't understand russian. What do you use your image gallery for?

Then make yourself happy - spend some week in Moscow with Russian girls  :wink: And there's not much to read in this gallery, just look at photos. This is a gallery for Russian IRC network DalNet(ru), so the people you see there are wasting best part of their life chatting  8O I've started this gallery two weeks ago, so there are still not too many photos...
Quote from: ChrisTTian
The link to my web site is http://www.tt-owners.de. A Page about a car from Aud called "Audi TT"

Very nice desing!  I used to drive TT once, nice car, but I'm a big fan of another German manufacturer :) http://sll.blood.ru/tmp/sll-525.jpg
Title: New Pics in Category
Post by: gti-the-sexy on January 23, 2003, 01:35:10 PM
how could I list the "new added images" for all categories, not for one by one category

for example last 20 added images list for all "4images"

thanks to SLL and Christ :)
Title: New Pics in Category
Post by: SLL on January 23, 2003, 02:01:49 PM
just remove if ($images_in_category) {
   echo "Found <b>$images_in_category</b> new images in category <b>$category_name</b>&nbsp;&nbsp;&nbsp;$category_link ...view category </a><br>";}


At the very end you could write something like echo "Total: $total_images_found found";
Title: New Pics in Category
Post by: ChrisTTian on January 23, 2003, 05:44:47 PM
gti-the-sexy

glad that my pm was some help for you ;-)

christian
Title: New Pics in Category
Post by: gti-the-sexy on January 24, 2003, 12:13:59 AM
ok then my last question :)

this code gives me last x images for x times
but I want it to give me last x images for 1 time :)

Code: [Select]

<?php 

define
&#40;'ROOT_PATH', './'&#41;; 
include&#40;ROOT_PATH.'global.php'&#41;; 
require&#40;ROOT_PATH.'includes/sessions.php'&#41;; 
$user_access get_permission&#40;&#41;; 
$cat_id_sql get_auth_cat_sql&#40;"auth_viewcat", "NOTIN"&#41;; 
$number_of_news 5

$sql "SELECT i.image_name, i.image_id, i.image_date, c.cat_name, u.user_name 
        FROM "
.IMAGES_TABLE." i, ".CATEGORIES_TABLE." c, ".USERS_TABLE." u 
        WHERE i.image_active = 1 AND i.cat_id NOT IN &#40;
$cat_id_sql&#41; AND i.cat_id = c.cat_id AND i.user_id = u.user_id $cat_match_sql 
        ORDER BY i.image_date DESC 
        LIMIT 
$number_of_news"
$result $site_db->query&#40;$sql&#41;; 
$new_images_list = array&#40;&#41;; 
$i 1
while &
#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123; 
  
$new_images_list[$i&#93; = $row; 
  
$i++; 
&
#125; 
$site_db->free_result&#40;&#41;; 


for &#40;$i = 1; $i <= $number_of_news; $i++&#41; &#123; 
  
if &#40;isset&#40;$new_images_list[$i&#93;&#41;&#41; &#123; 

$result $site_db->query&#40;$sql&#41;; 
 
while &#40;$row = $site_db->fetch_array&#40;$result&#41;&#41; &#123;  
 
$image_id = &#40;$row['image_id'&#93;&#41;;
 
$image_name = &#40;$row['image_name'&#93;&#41;;
$image_link = &#40;"<a href=\"" . ROOT_PATH . "details.php?image_id=" . $image_id . "\">"&#41;;
$image_date format_date&#40;$config['date_format'&#93;." ".$config['time_format'&#93;,$new_images_list[$i&#93;['image_date'&#93;&#41;; 
$news = &#40;"&#58;&#58; <b>" . $new_images_list[$i&#93;['image_name'&#93; . "</b> &#40; <b>" . $new_images_list[$i&#93;['cat_name'&#93; . " </b>&#41; <br>" &#41;; 


echo "<ul><b>$image_name</b> &nbsp;&nbsp;&nbsp;$image_link ...view image </a></ul>";

  &
#125; 
&#125;
&#125; 
?>



this code gives me last 5 images for 5 times :)
I WANT TO LIST LAST 5 IMAGES FOR 1 TIME

please help me with this code , without any other codes
Title: New Pics in Category
Post by: SLL on January 24, 2003, 08:53:10 AM
Quote from: gti-the-sexy
please help me with this code , without any other codes

you shouldn't remove sql query, do exactly, what I told you above
Title: New Pics in Category
Post by: gti-the-sexy on January 24, 2003, 11:25:54 AM
of course I did, but it removes only "xxx found in xxx category" sentence and list the new X images for X categories

I dont want to list categories by categories

ONLY LIST LAST X IMAGES FOR ALL 4IMAGES

thanks for help
Title: New Pics in Category
Post by: Slammer on June 11, 2003, 02:09:09 PM
hello,

i got the get_new_pics.php working, but now i want to 'load' it in my home.html. i did this through the following code:

<?php include("get_new_pics.php"); ?>

but when i load my page, it gives the following error:

Fatal error: Cannot redeclare addslashes_array() (previously declared in /blablabla/global.php:32) in /blablabla/global.php on line 32

can someone help me with this? when i load the get_new_pics.php from where it's at, it works, but it doesn't when i try loading it up through home.html...

grtz
Title: New Pics in Category
Post by: V@no on June 11, 2003, 02:12:39 PM
if u want include it into template that way, then u can comment those lines:
Code: [Select]
define('ROOT_PATH', './');
include(ROOT_PATH.'global.php');
require(ROOT_PATH.'includes/sessions.php');
$user_access = get_permission();
Title: New Pics in Category
Post by: Slammer on June 11, 2003, 02:55:57 PM
thnx for your reply V@no, but where should i insert this code? in the home.html?
because this code is already in my get_new_pics.php
http://mobile-snapshots.com/Gallery/get_new_pics.php
Title: New Pics in Category
Post by: V@no on June 11, 2003, 08:37:00 PM
Quote from: Slammer
thnx for your reply V@no, but where should i insert this code? in the home.html?
because this code is already in my get_new_pics.php
http://mobile-snapshots.com/Gallery/get_new_pics.php

hum? insert? I didnt say insert, I said comment (delete, erase, destroy) ;)
Title: New Pics in Category
Post by: Slammer on June 11, 2003, 08:46:16 PM
:cry:
it gives me another error after i commented (sorry, didn't know that it ment deleting :lol: ) the codes.
it now says:

Fatal error: Call to a member function on a non-object in /blablabla/get_new_pics.php on line 20

is there any other way to include this in a site?
thnx.
Title: ???
Post by: Fugaziman on June 11, 2003, 10:41:55 PM
I just noticed this post and couldn't help noticing it's very similar to a Mod post I made a little while ago.  :?:

http://www.4homepages.de/forum/viewtopic.php?t=5654

My mode does not do any extra Database Calls (slowing your page load time)

You can see it in action on my web page - Left side.
Just thought it may help.
I'll go now  :D
Title: Listing without thumbnails
Post by: Koosje on July 27, 2007, 10:14:11 AM
How is it possible to have a listing without thumbnails extra besides the one with thumbnails? This as a short overview of all or searched pics.