Author Topic: New Pics in Category  (Read 34038 times)

0 Members and 1 Guest are viewing this topic.

Offline ChrisTTian

  • Newbie
  • *
  • Posts: 29
    • View Profile
New Pics in Category
« 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

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
Quick code....
« Reply #1 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:

Offline ChrisTTian

  • Newbie
  • *
  • Posts: 29
    • View Profile
New Pics in Category
« Reply #2 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

Offline ChrisTTian

  • Newbie
  • *
  • Posts: 29
    • View Profile
New Pics in Category
« Reply #3 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

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #4 on: January 20, 2003, 03:38:40 PM »
thanx a lot SLL
but how could I link the image names??

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #5 on: January 20, 2003, 07:17:27 PM »
help please for linking

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
New Pics in Category
« Reply #6 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>";
?>


Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #7 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

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #8 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 :)

Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
New Pics in Category
« Reply #9 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.

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #10 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?"
---------------

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #11 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; 
?>


Offline SLL

  • Hero Member
  • *****
  • Posts: 585
    • View Profile
New Pics in Category
« Reply #12 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....

Offline gti-the-sexy

  • Newbie
  • *
  • Posts: 33
    • View Profile
New Pics in Category
« Reply #13 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

Offline ChrisTTian

  • Newbie
  • *
  • Posts: 29
    • View Profile
New Pics in Category
« Reply #14 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>"
?>