Advanced search  

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Pages: [1]   Go Down

Author Topic: Change a query to sort "lastalb function" by DESC  (Read 2734 times)

0 Members and 1 Guest are viewing this topic.

net

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 88
Change a query to sort "lastalb function" by DESC
« on: May 10, 2009, 08:15:49 pm »

Hi,

All my albums have sort order "Date Descending" thus i've uploaded all my files in such fasion that the first picture in the album always is the last one uploaded in that particular album.

This works fine when browsing normally through the gallery.

However, i've added a button to call "Last Updated Albums" which basicly shows all the new albums created. In this case all the thumbnails for the albums are the first picture uploaded, which means the default sort order here is date ascending. I was wondering how i could change this behaviour.

The code i use to call "Last updated album" is following:

config > themes settings > Custom menu link name
Code: [Select]
Last updated albumsconfig > themes settings > Custom menu link URL 
Code: [Select]
thumbnails.php?album=lastalb
I'm guessing it could be as easy as just changing the link url to something that tells it to sort by descending? Otherwise it's probably possible to modify the code part in include/functions.inc.php
Code: [Select]
        case 'lastalb': // Last albums to which uploads
                if ($META_ALBUM_SET && $CURRENT_CAT_NAME) {
                        $album_name = $lang_meta_album_names['lastalb'].' - '. $CURRENT_CAT_NAME;
                } else {
                        $album_name = $lang_meta_album_names['lastalb'];
                }


                $META_ALBUM_SET = str_replace( "aid", $CONFIG['TABLE_PICTURES'].".aid" , $META_ALBUM_SET );

                $query = "SELECT count({$CONFIG['TABLE_ALBUMS']}.aid) FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' $META_ALBUM_SET GROUP  BY {$CONFIG['TABLE_PICTURES']}.aid";

                $result = cpg_db_query($query);
                $count = mysql_num_rows($result);
                mysql_free_result($result);

                $query = "SELECT *,{$CONFIG['TABLE_ALBUMS']}.title AS title,{$CONFIG['TABLE_ALBUMS']}.aid AS aid FROM {$CONFIG['TABLE_PICTURES']},{$CONFIG['TABLE_ALBUMS']} WHERE {$CONFIG['TABLE_PICTURES']}.aid = {$CONFIG['TABLE_ALBUMS']}.aid AND approved = 'YES' $META_ALBUM_SET GROUP BY {$CONFIG['TABLE_PICTURES']}.aid ORDER BY {$CONFIG['TABLE_PICTURES']}.ctime DESC $limit";
                $result = cpg_db_query($query);
                $rowset = cpg_db_fetch_rowset($result);
                mysql_free_result($result);

                if ($set_caption) build_caption($rowset,array('ctime'));

                $rowset = CPGPluginAPI::filter('thumb_caption_lastalb',$rowset);

                return $rowset;
                break;

To add the sorting somehow?

I'm no professional! Would love some help.

Thank you.
Logged

net

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 88
Re: Change a query to sort "lastalb function" by DESC
« Reply #1 on: May 11, 2009, 07:09:42 pm »

No one yet? And i though this was an easy question, was i wrong? :) I've searched and came up with nothing!

If it's impossible, please tell me so!
Logged

Nibbler

  • Guest
Re: Change a query to sort "lastalb function" by DESC
« Reply #2 on: May 11, 2009, 07:57:39 pm »

Not sure I understand the question. You want the album thumb to be the first uploaded instead of the last uploaded?

The easiest way to do this would be to set the album thumbnail you want in album properties for each album. If you want to make it automatic then that's not the right code to be changing anyway. You'd want to change index.php

Code: [Select]
max( p.pid )  AS last_pid

Change max to min (twice).
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Change a query to sort "lastalb function" by DESC
« Reply #3 on: May 11, 2009, 09:39:25 pm »

No one yet?
This is not a hotline!
Logged

net

  • Coppermine regular visitor
  • **
  • Offline Offline
  • Posts: 88
Re: Change a query to sort "lastalb function" by DESC
« Reply #4 on: May 12, 2009, 09:32:42 am »

Not sure I understand the question. You want the album thumb to be the first uploaded instead of the last uploaded?

The easiest way to do this would be to set the album thumbnail you want in album properties for each album. If you want to make it automatic then that's not the right code to be changing anyway. You'd want to change index.php

Code: [Select]
max( p.pid )  AS last_pid

Change max to min (twice).

No actually just the reverse, i want the last image uploaded to the album to be the album thumbnail. This works perfectly using the normal browsing, but when calling the function "Lastalb"
Code: [Select]
thumbnails.php?album=lastalb it displays all albums with the first image that was uploaded into that album. Since i have default sort order desc i upload all my image-sets in reverse order.

I know i could solve this by manually setting each album thumbnail, but knowing the amount of extra load on queries it generates + the manual work of setting 3600+ album thumbnails, id rather just find the code for it :)

The changes you recommended didn't work for me, i'm still unsure if i need to touch index.php, since i don't have any trouble with it... The trouble i have is when calling the function "lastalb" which is in the functions.inc.php. I'm guessing it sorts by time, but is there anyway to get it to sort by time + put album thumbnails in desc order instead of the default asc order?

Quote
This is not a hotline!

Never though it was! I'm sorry if it came of cold, i usually get replies really fast when things are simple, maybe this isn't as simple as i though! Thanks for the continous support.
Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 20 queries.