forum.coppermine-gallery.net

Support => cpg1.3.x Support => Older/other versions => cpg1.3 Miscellaneous => Topic started by: mattoz22 on October 17, 2005, 02:59:45 am

Title: Reverse the order of the albums?
Post by: mattoz22 on October 17, 2005, 02:59:45 am
Hi,

I have added around 80 albums to my gallery.... Due to the way I added them currently it losts the oldest at the top and the newest at the bottom of the page.

Is there any easy way to make the gallery reverse the order of the albums? I dont want to use the admin panel to manually change the order of over 80 albums, I simply need it to reverse the order...

?

Thanks for any help! (have searched and not found what I need)..
Title: Re: Reverse the order of the albums?
Post by: mattoz22 on October 20, 2005, 08:39:05 am
Nobody?
Title: Re: Reverse the order of the albums?
Post by: Joachim Müller on October 20, 2005, 09:06:48 am
are those 80 albums all in one category (or no category at all)? This is overkill, I recommend giving your site some structure that makes sense, instead of just reversing chaos (as you will still get chaos no matter what). As a nice side-effect, it'll get easier to change the order in the albums manager. Post a link to your site if you want detailed recommendations. After all, post the link anyway please.
If you really need just the reverse, you could come up with a mod that reverses the order in the code that displays index.php, however I recommend running a query once that does this.
Title: Re: Reverse the order of the albums?
Post by: mattoz22 on October 20, 2005, 03:39:23 pm
Due to the nature of the site I do only have one category....

Here it is... www.ozziness.com

I would rather put something into the code somewhere to simply reverse it, if thats somehow possible?
Title: Re: Reverse the order of the albums?
Post by: Stramm on October 20, 2005, 04:31:51 pm
OK, in index php find in the function list_albums()
Code: [Select]
' ORDER BY a.pos '.and replace with
Code: [Select]
' ORDER BY a.pos DESC '.
the second occurance doesn't matter cause you don't use cats: That should do ;)
Title: Re: Reverse the order of the albums?
Post by: Abbas Ali on October 20, 2005, 04:42:14 pm
As GauGau already said you have two options. First changing the query on index.php which retrieves the album data from database and second running a query/script for once which will change the positions of albums directly in the database. Both the methods are explained below.

Method 1 (Chaning query on index.php)
Edit index.php

Replace

Code: [Select]
$sql = 'SELECT a.aid, a.title, a.description, visibility, filepath, '.
           'filename, url_prefix, pwidth, pheight '.
           'FROM '.$CONFIG['TABLE_ALBUMS'].' as a '.
           'LEFT JOIN '.$CONFIG['TABLE_PICTURES'].' as p '.
           'ON a.thumb=p.pid '.
           'WHERE category='.$cat.$album_filter.
           ' ORDER BY a.pos '.
           $limit;

with

Code: [Select]
$sql = 'SELECT a.aid, a.title, a.description, visibility, filepath, '.
           'filename, url_prefix, pwidth, pheight '.
           'FROM '.$CONFIG['TABLE_ALBUMS'].' as a '.
           'LEFT JOIN '.$CONFIG['TABLE_PICTURES'].' as p '.
           'ON a.thumb=p.pid '.
           'WHERE category='.$cat.$album_filter.
           ' ORDER BY a.pos DESC '.
           $limit;

Method 2 (Changing the pos in database)
Do take a backup of albums table before running this code

Create a new script reverse.php with following code and place the script in coppermine root folder.

Code: [Select]
<?php
define
('IN_COPPERMINE'true);
define('LOGOUT_PHP'true);
require(
'include/init.inc.php');
if (!
GALLERY_ADMIN_MODE) {
  
cpg_die(ERROR$lang_errors['perm_denied'], __FILE____LINE__);
}
$query "SELECT count(aid) AS count FROM {$CONFIG['TABLE_ALBUMS']}";
$result db_query($query);
$row mysql_fetch_assoc($result);
$albCount $row['count'];

$query "SELECT pos,aid, title FROM {$CONFIG['TABLE_ALBUMS']} ORDER BY pos ASC";
$result db_query($query);
while (
$row mysql_fetch_array($result)) {
  
$newPos 100 $albCount;
  
$aid $row['aid'];
  
$sql "UPDATE {$CONFIG['TABLE_ALBUMS']} SET pos = '$newPos' WHERE aid = '$aid'";
  
$albCount--;
  
$update db_query($sql);
  if (
$update) {
    echo 
"Album '{$row['title']}'  =>   Old pos={$row['pos']}  New pos=$newPos<br>";
  }
}
?>


After creating the script run it once. This will reverse the order of your albums. After successfully reversing the order of albums i recommend deleting the script.

NOTE:

Abbas

P.S: Stramm already posted the first solution when i was composing this message. Anyways i am still posting.
Title: Re: Reverse the order of the albums?
Post by: mattoz22 on October 21, 2005, 02:03:44 am
Thank you both so much for your time. Both methods worked perfectly.

I editted index.php as a quick fix but will eventually get around to doing it the proper way... and hey one day I might even use categories ;)
Title: Re: Reverse the order of the albums?
Post by: calvin123 on October 25, 2005, 12:34:28 am
Hi, I tried your changes and they work perfectly, but to make it a consistent solution I would
propose that you also change the "list_cat_albums"-function and reverse the order albums
are displayed on the main-page.

I added at the end of the "sql"-string also a "ORDER BY pos DESC" - now it looks as follows:

$sql = "SELECT a.aid, a.title, a.description, visibility, filepath, " . "
           filename, url_prefix, pwidth, pheight " . "
           FROM {$CONFIG['TABLE_ALBUMS']} as a " . "
           LEFT JOIN {$CONFIG['TABLE_PICTURES']} as p
           ON thumb=pid " . "WHERE category = '$cat' ORDER BY pos DESC " . "$limit";

Greetings Stefan
P.S.
(Sorry for my bad english, but I'm a little bit out of training)