aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2003-09-05 19:27:45 +0000
committerz0rglub <z0rglub@piwigo.org>2003-09-05 19:27:45 +0000
commit4f6dabea73678e2dad683d160eef8fedc562e8c6 (patch)
treef650fad5fcac6e6639bb027e8a5e8b587deb7356
parent839771e0b692ebf468fcfbecec95d6e27c439394 (diff)
Correcting a bug in special categories (favorites, most seen, most
recent... non numeric categories) : when a picture is linked to more than one category, it's only displayed once. git-svn-id: http://piwigo.org/svn/trunk@64 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r--category.php9
-rw-r--r--include/functions_category.inc.php4
-rw-r--r--picture.php25
3 files changed, 22 insertions, 16 deletions
diff --git a/category.php b/category.php
index 2264be614..1db16ffa0 100644
--- a/category.php
+++ b/category.php
@@ -233,10 +233,10 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
{
$array_cat_directories = array();
- $query = 'SELECT id,file,date_available,tn_ext,name,filesize';
- $query.= ',storage_category_id,category_id';
- $query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query = 'SELECT distinct(id),file,date_available,tn_ext,name,filesize';
+ $query.= ',storage_category_id';
+ $query.= ' FROM '.PREFIX_TABLE.'images AS i';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$page['start'].','.$page['nb_image_page'];
@@ -251,6 +251,7 @@ if ( isset( $page['cat'] ) and $page['cat_nb_images'] != 0 )
$line_number = 1;
while ( $row = mysql_fetch_array( $result ) )
{
+ // retrieving the storage dir of the picture
if ( $array_cat_directories[$row['storage_category_id']] == '' )
{
$array_cat_directories[$row['storage_category_id']] =
diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php
index dffb6c337..33b3f92fc 100644
--- a/include/functions_category.inc.php
+++ b/include/functions_category.inc.php
@@ -493,9 +493,9 @@ function initialize_category( $calling_page = 'category' )
{
$page['title'] = $lang['favorites'];
- $page['where'] = ', '.PREFIX_TABLE.'favorites';
+ $page['where'] = ', '.PREFIX_TABLE.'favorites AS fav';
$page['where'].= ' WHERE user_id = '.$user['id'];
- $page['where'].= ' AND image_id = id';
+ $page['where'].= ' AND fav.image_id = id';
$query = 'SELECT COUNT(*) AS nb_total_images';
$query.= ' FROM '.PREFIX_TABLE.'favorites';
diff --git a/picture.php b/picture.php
index 96605607b..b9ec3410e 100644
--- a/picture.php
+++ b/picture.php
@@ -40,9 +40,13 @@ $cat_directory = $page['cat_dir']; // by default
//------------------------------------- main picture information initialization
$query = 'SELECT id,date_available,comment,hit,keywords';
$query.= ',author,name,file,date_creation,filesize,width,height';
-$query.= ',storage_category_id,category_id';
+$query.= ',storage_category_id';
+if ( is_numeric( $page['cat'] ) )
+{
+ $query.= ',category_id';
+}
$query.= ' FROM '.PREFIX_TABLE.'images';
-$query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+$query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id';
$query.= $page['where'];
$query.= ' AND id = '.$_GET['image_id'];
$query.= $conf['order_by'];
@@ -64,9 +68,9 @@ $page['category_id'] = $row['category_id'];
$page['keywords'] = $row['keywords'];
$page['storage_category_id'] = $row['storage_category_id'];
// retrieving the number of the picture in its category (in order)
-$query = 'SELECT id';
+$query = 'SELECT DISTINCT(id)';
$query.= ' FROM '.PREFIX_TABLE.'images';
-$query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+$query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ';';
@@ -128,7 +132,8 @@ if ( isset( $_GET['add_fav'] ) )
}
$query = 'SELECT id';
$query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
+ $query.= ' ON id = ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$page['num'].',1';
@@ -211,9 +216,9 @@ else
if ( $page['num'] >= 1 )
{
$prev = $page['num'] - 1;
- $query = 'SELECT id,name,file,tn_ext,storage_category_id';
+ $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id';
$query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$prev.',1';
@@ -457,7 +462,7 @@ if ( $page['cat'] == 'fav' )
$vtp->closeSession( $handle, 'favorite' );
}
//------------------------------------ admin link for information modifications
-if ( $user['status'] == "admin" and is_numeric( $page['cat'] ) )
+if ( $user['status'] == 'admin' )
{
$vtp->addSession( $handle, 'modification' );
$url = './admin/admin.php?page=picture_modify&amp;cat_id='.$page['cat'];
@@ -469,9 +474,9 @@ if ( $user['status'] == "admin" and is_numeric( $page['cat'] ) )
if ( $page['num'] < $page['cat_nb_images']-1 )
{
$next = $page['num'] + 1;
- $query = 'SELECT id,name,file,tn_ext,storage_category_id';
+ $query = 'SELECT DISTINCT(id),name,file,tn_ext,storage_category_id';
$query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id=ic.image_id';
$query.= $page['where'];
$query.= $conf['order_by'];
$query.= ' LIMIT '.$next.',1';