aboutsummaryrefslogtreecommitdiffstats
path: root/admin
diff options
context:
space:
mode:
authorz0rglub <z0rglub@piwigo.org>2004-01-15 23:19:51 +0000
committerz0rglub <z0rglub@piwigo.org>2004-01-15 23:19:51 +0000
commitb8d74dde50298cbe4f99ada6c87b363ee9344b86 (patch)
tree66d07e15bc1ab802382fa03f4869d695854a2440 /admin
parent384ec739f6c11ab82f9a57e9398e954206c7a7ca (diff)
improved function update_category essentially by using INNER JOIN instead of
LEFT JOIN git-svn-id: http://piwigo.org/svn/branches/release-1_3@281 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'admin')
-rw-r--r--admin/include/functions.php20
1 files changed, 8 insertions, 12 deletions
diff --git a/admin/include/functions.php b/admin/include/functions.php
index ea2669cb0..518cd4c73 100644
--- a/admin/include/functions.php
+++ b/admin/include/functions.php
@@ -379,26 +379,22 @@ function update_category( $id = 'all' )
$query.= ' FROM '.PREFIX_TABLE.'image_category';
$query.= ' WHERE category_id = '.$id;
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
- $query = 'UPDATE '.PREFIX_TABLE.'categories';
- $query.= ' SET nb_images = '.$row['nb_images'];
- $query.= ' WHERE id = '.$id;
- $query.= ';';
- mysql_query( $query );
+ list( $nb_images ) = mysql_fetch_array( mysql_query( $query ) );
// updating the date_last
- $query = 'SELECT date_available';
+ $query = 'SELECT MAX(date_available) AS date_available';
$query.= ' FROM '.PREFIX_TABLE.'images';
- $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
+ $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id';
$query.= ' WHERE category_id = '.$id;
- $query.= ' ORDER BY date_available DESC';
- $query.= ' LIMIT 0,1';
$query.= ';';
- $row = mysql_fetch_array( mysql_query( $query ) );
+ list( $date_available ) = mysql_fetch_array( mysql_query( $query ) );
+
$query = 'UPDATE '.PREFIX_TABLE.'categories';
- $query.= " SET date_last = '".$row['date_available']."'";
+ $query.= " SET date_last = '".$date_available."'";
+ $query.= ' SET nb_images = '.$nb_images;
$query.= ' WHERE id = '.$id;
$query.= ';';
mysql_query( $query );
+
// updating the representative_picture_id : if the representative
// picture of the category is not any more linked to the category, we
// have to set representative_picture_id to NULL