Change a query to sort "lastalb function" by DESC Change a query to sort "lastalb function" by DESC
 

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Main Menu

Change a query to sort "lastalb function" by DESC

Started by net, May 10, 2009, 08:15:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

net

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 Last updated albums
config > themes settings > Custom menu link URL  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         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.

net

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!

Nibbler

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


max( p.pid )  AS last_pid


Change max to min (twice).

Joachim Müller


net

Quote from: Nibbler 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


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" 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?

QuoteThis 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.