Index: trunk/include/category_cats.inc.php
===================================================================
--- trunk/include/category_cats.inc.php	(revision 27335)
+++ trunk/include/category_cats.inc.php	(revision 27336)
@@ -134,5 +134,4 @@
 if ($conf['display_fromto'])
 {
-  $dates_of_category = array();
   if (count($category_ids) > 0)
   {
@@ -140,6 +139,6 @@
 SELECT
     category_id,
-    MIN(date_creation) AS date_creation_min,
-    MAX(date_creation) AS date_creation_max
+    MIN(date_creation) AS `from`,
+    MAX(date_creation) AS `to`
   FROM '.IMAGE_CATEGORY_TABLE.'
     INNER JOIN '.IMAGES_TABLE.' ON image_id = id
@@ -156,12 +155,5 @@
   GROUP BY category_id
 ;';
-    $result = pwg_query($query);
-    while ($row = pwg_db_fetch_assoc($result))
-    {
-      $dates_of_category[ $row['category_id'] ] = array(
-        'from' => $row['date_creation_min'],
-        'to'   => $row['date_creation_max'],
-        );
-    }
+    $dates_of_category = query2array($query, 'category_id');
   }
 }
Index: trunk/include/dblayer/functions_mysql.inc.php
===================================================================
--- trunk/include/dblayer/functions_mysql.inc.php	(revision 27335)
+++ trunk/include/dblayer/functions_mysql.inc.php	(revision 27336)
@@ -761,3 +761,73 @@
 }
 
+/**
+ * Builds an data array from a SQL query.
+ * Depending on $key_name and $value_name it can return :
+ *
+ *    - an array of arrays of all fields (key=null, value=null)
+ *        array(
+ *          array('id'=>1, 'name'=>'DSC8956', ...),
+ *          array('id'=>2, 'name'=>'DSC8957', ...),
+ *          ...
+ *          )
+ *
+ *    - an array of a single field (key=null, value='...')
+ *        array('DSC8956', 'DSC8957', ...)
+ *
+ *    - an associative array of array of all fields (key='...', value=null)
+ *        array(
+ *          'DSC8956' => array('id'=>1, 'name'=>'DSC8956', ...),
+ *          'DSC8957' => array('id'=>2, 'name'=>'DSC8957', ...),
+ *          ...
+ *          )
+ *
+ *    - an associative array of a single field (key='...', value='...')
+ *        array(
+ *          'DSC8956' => 1,
+ *          'DSC8957' => 2,
+ *          ...
+ *          )
+ *
+ * @since 2.6
+ *
+ * @param string $query
+ * @param string $key_name
+ * @param string $value_name
+ * @return array
+ */
+function query2array($query, $key_name=null, $value_name=null)
+{
+  $result = pwg_query($query);
+  $data = array();
+
+  if (isset($key_name))
+  {
+    if (isset($value_name))
+    {
+      while ($row = pwg_db_fetch_assoc($result))
+        $data[ $row[$key_name] ] = $row[$value_name];
+    }
+    else
+    {
+      while ($row = pwg_db_fetch_assoc($result))
+        $data[ $row[$key_name] ] = $row;
+    }
+  }
+  else
+  {
+    if (isset($value_name))
+    {
+      while ($row = pwg_db_fetch_assoc($result))
+        $data[] = $row[$value_name];
+    }
+    else
+    {
+      while ($row = pwg_db_fetch_assoc($result))
+        $data[] = $row;
+    }
+  }
+
+  return $data;
+}
+
 ?>
Index: trunk/include/dblayer/functions_mysqli.inc.php
===================================================================
--- trunk/include/dblayer/functions_mysqli.inc.php	(revision 27335)
+++ trunk/include/dblayer/functions_mysqli.inc.php	(revision 27336)
@@ -800,3 +800,73 @@
 }
 
+/**
+ * Builds an data array from a SQL query.
+ * Depending on $key_name and $value_name it can return :
+ *
+ *    - an array of arrays of all fields (key=null, value=null)
+ *        array(
+ *          array('id'=>1, 'name'=>'DSC8956', ...),
+ *          array('id'=>2, 'name'=>'DSC8957', ...),
+ *          ...
+ *          )
+ *
+ *    - an array of a single field (key=null, value='...')
+ *        array('DSC8956', 'DSC8957', ...)
+ *
+ *    - an associative array of array of all fields (key='...', value=null)
+ *        array(
+ *          'DSC8956' => array('id'=>1, 'name'=>'DSC8956', ...),
+ *          'DSC8957' => array('id'=>2, 'name'=>'DSC8957', ...),
+ *          ...
+ *          )
+ *
+ *    - an associative array of a single field (key='...', value='...')
+ *        array(
+ *          'DSC8956' => 1,
+ *          'DSC8957' => 2,
+ *          ...
+ *          )
+ *
+ * @since 2.6
+ *
+ * @param string $query
+ * @param string $key_name
+ * @param string $value_name
+ * @return array
+ */
+function query2array($query, $key_name=null, $value_name=null)
+{
+  $result = pwg_query($query);
+  $data = array();
+
+  if (isset($key_name))
+  {
+    if (isset($value_name))
+    {
+      while ($row = $result->fetch_assoc())
+        $data[ $row[$key_name] ] = $row[$value_name];
+    }
+    else
+    {
+      while ($row = $result->fetch_assoc())
+        $data[ $row[$key_name] ] = $row;
+    }
+  }
+  else
+  {
+    if (isset($value_name))
+    {
+      while ($row = $result->fetch_assoc())
+        $data[] = $row[$value_name];
+    }
+    else
+    {
+      while ($row = $result->fetch_assoc())
+        $data[] = $row;
+    }
+  }
+
+  return $data;
+}
+
 ?>
Index: trunk/include/functions.inc.php
===================================================================
--- trunk/include/functions.inc.php	(revision 27335)
+++ trunk/include/functions.inc.php	(revision 27336)
@@ -1,3 +1,3 @@
-<?php 
+<?php
 // +-----------------------------------------------------------------------+
 // | Piwigo - a PHP based photo gallery                                    |
@@ -482,7 +482,7 @@
     return $date1->diff($date2);
   }
-  
+
   $diff = new stdClass();
-  
+
   //Make sure $date1 is ealier
   $diff->invert = $date2 < $date1;
@@ -491,5 +491,5 @@
     list($date1, $date2) = array($date2, $date1);
   }
-  
+
   //Calculate R values
   $R = ($date1 <= $date2 ? '+' : '-');
@@ -525,5 +525,5 @@
     $date1->modify('-1 '.$period);
   }
-  
+
   list($diff->y, $diff->m, $diff->d, $diff->h) = array_values($periods);
 
@@ -532,5 +532,5 @@
   $diff->i = floor($diff->s/60);
   $diff->s = $diff->s - $diff->i*60;
-  
+
   return $diff;
 }
@@ -570,10 +570,10 @@
         $tok = strtok('- :/');
       }
-      
+
       if (count($ymdhms)<3) return false;
       if (!isset($ymdhms[3])) $ymdhms[3] = 0;
       if (!isset($ymdhms[4])) $ymdhms[4] = 0;
       if (!isset($ymdhms[5])) $ymdhms[5] = 0;
-      
+
       $date = new DateTime();
       $date->setDate($ymdhms[0], $ymdhms[1], $ymdhms[2]);
@@ -596,5 +596,5 @@
 {
   global $lang;
-  
+
   $date = str2DateTime($original, $format);
 
@@ -609,9 +609,9 @@
     $print.= $lang['day'][ $date->format('w') ].' ';
   }
-  
+
   $print.= $date->format('j');
   $print.= ' '.$lang['month'][ $date->format('n') ];
   $print.= ' '.$date->format('Y');
-  
+
   if ($show_time)
   {
@@ -644,8 +644,8 @@
     return l10n('N/A');
   }
-  
+
   $now = new DateTime();
   $diff = dateDiff($now, $date);
-  
+
   $chunks = array(
     'year' => $diff->y,
@@ -657,5 +657,5 @@
     'second' => $diff->s,
   );
-  
+
   // DateInterval does not contain the number of weeks
   if ($with_week)
@@ -664,7 +664,7 @@
     $chunks['day'] = $chunks['day'] - $chunks['week']*7;
   }
-  
+
   $j = array_search($stop, array_keys($chunks));
-  
+
   $print = ''; $i=0;
   foreach ($chunks as $name => $value)
@@ -680,7 +680,7 @@
     $i++;
   }
-  
+
   $print = trim($print);
-  
+
   if ($with_text)
   {
@@ -934,5 +934,5 @@
   WHERE user_id = '.$user['id'].'
 ;';
-  $in_caddie = array_from_query($query, 'element_id');
+  $in_caddie = query2array($query, null, 'element_id');
 
   $caddiables = array_diff($elements_id, $in_caddie);
@@ -1043,5 +1043,5 @@
  * returns a string formated with l10n elements.
  * it is usefull to "prepare" a text and translate it later
- * @see get_l10n_args() 
+ * @see get_l10n_args()
  *
  * @param array $key_args one l10n_args element or array of l10n_args elements
@@ -1153,5 +1153,5 @@
     $conf[ $row['param'] ] = $val;
   }
-  
+
   trigger_action('load_conf', $condition);
 }
@@ -1166,11 +1166,9 @@
 {
   $query = '
-SELECT
-    param,
-    value
+SELECT param
   FROM '.CONFIG_TABLE.'
   WHERE param = \''.$param.'\'
 ;';
-  $params = array_from_query($query, 'param');
+  $params = query2array($query, null, 'param');
 
   if (count($params) == 0)
@@ -1204,5 +1202,5 @@
 {
   global $conf;
-  
+
   if (!is_array($params))
   {
@@ -1213,5 +1211,5 @@
     return;
   }
-  
+
   $query = '
 DELETE FROM '.CONFIG_TABLE.'
@@ -1219,5 +1217,5 @@
 ;';
   pwg_query($query);
-  
+
   foreach ($params as $param)
   {
@@ -1245,67 +1243,4 @@
 
 /**
- * Builds an data array from a SQL query.
- * Depending on $key_name and $value_name it can return :
- *
- *    - an array of arrays of all fields (key=null, value=null)
- *        array(
- *          array('id'=>1, 'name'=>'DSC8956', ...),
- *          array('id'=>2, 'name'=>'DSC8957', ...),
- *          ...
- *          )
- *
- *    - an array of a single field (key=null, value='...')
- *        array('DSC8956', 'DSC8957', ...)
- *
- *    - an associative array of array of all fields (key='...', value=null)
- *        array(
- *          'DSC8956' => array('id'=>1, 'name'=>'DSC8956', ...),
- *          'DSC8957' => array('id'=>2, 'name'=>'DSC8957', ...),
- *          ...
- *          )
- *
- *    - an associative array of a single field (key='...', value='...')
- *        array(
- *          'DSC8956' => 1,
- *          'DSC8957' => 2,
- *          ...
- *          )
- *
- * @since 2.6
- *
- * @param string $query
- * @param string $key_name
- * @param string $value_name
- * @return array
- */
-function query2array($query, $key_name=null, $value_name=null)
-{
-  $result = pwg_query($query);
-  $data = array();
-
-  while ($row = pwg_db_fetch_assoc($result))
-  {
-    if (isset($value_name))
-    {
-      $value = $row[ $value_name ];
-    }
-    else
-    {
-      $value = $row;
-    }
-    if (isset($key_name))
-    {
-      $data[ $row[$key_name] ] = $value;
-    }
-    else
-    {
-      $data[] = $value;
-    }
-  }
-
-  return $data;
-}
-
-/**
  * creates an simple hashmap based on a SQL query.
  * choose one to be the key, another one to be the value.
@@ -1369,5 +1304,5 @@
     while ($row = pwg_db_fetch_assoc($result))
     {
-      $array[] = $row;      
+      $array[] = $row;
     }
   }
@@ -1494,5 +1429,5 @@
 {
   global $user, $language_files;
-  
+
   if ( !empty($dirname) and !empty($filename) )
   {
@@ -1574,5 +1509,5 @@
       if ( !isset($lang) ) $lang=array();
       if ( !isset($lang_info) ) $lang_info=array();
-      
+
       $parent_language = !empty($load_lang_info['parent']) ? $load_lang_info['parent'] : (
                             !empty($lang_info['parent']) ? $lang_info['parent'] : null );
@@ -2066,5 +2001,5 @@
     list($user['nb_available_comments']) = pwg_db_fetch_row(pwg_query($query));
 
-    single_update(USER_CACHE_TABLE, 
+    single_update(USER_CACHE_TABLE,
       array('nb_available_comments'=>$user['nb_available_comments']),
       array('user_id'=>$user['id'])
@@ -2087,13 +2022,13 @@
 {
   $replace_chars = create_function('$m', 'return ord(strtolower($m[1]));');
-  
+
   // add dot before groups of letters (version_compare does the same thing)
   $a = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $a);
   $b = preg_replace('#([0-9]+)([a-z]+)#i', '$1.$2', $b);
-  
+
   // apply ord() to any single letter
   $a = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $a);
   $b = preg_replace_callback('#\b([a-z]{1})\b#i', $replace_chars, $b);
-  
+
   if (empty($op))
   {
Index: trunk/include/functions_tag.inc.php
===================================================================
--- trunk/include/functions_tag.inc.php	(revision 27335)
+++ trunk/include/functions_tag.inc.php	(revision 27336)
@@ -71,5 +71,5 @@
   GROUP BY tag_id
 ;';
-  $tag_counters = simple_hash_from_query($query, 'tag_id', 'counter');
+  $tag_counters = query2array($query, 'tag_id', 'counter');
 
   if ( empty($tag_counters) )
@@ -234,5 +234,5 @@
   $query .= "\n".(empty($order_by) ? $conf['order_by'] : $order_by);
 
-  return array_from_query($query, 'id');
+  return query2array($query, null, 'id');
 }
 
@@ -321,11 +321,5 @@
     OR ', $where_clauses);
 
-  $result = pwg_query($query);
-  $tags = array();
-  while ($row = pwg_db_fetch_assoc($result))
-  {
-    $tags[] = $row;
-  }
-  return $tags;
+  return query2array($query);
 }
 
Index: trunk/include/section_init.inc.php
===================================================================
--- trunk/include/section_init.inc.php	(revision 27335)
+++ trunk/include/section_init.inc.php	(revision 27336)
@@ -93,5 +93,5 @@
   // url compatibility with versions below 1.6
   if ( isset($_GET['image_id'])
-       and isset($_GET['cat']) 
+       and isset($_GET['cat'])
        and is_numeric($_GET['cat']) )
   {
@@ -103,5 +103,5 @@
     redirect($url);
   }
-  
+
   $token = $tokens[$next_token];
   $next_token++;
@@ -243,5 +243,5 @@
   {
     $page = array_merge(
-      $page, 
+      $page,
       array(
         'comment' => trigger_event(
@@ -293,6 +293,6 @@
         "\n  AND"
         );
-        
-        $subcat_ids = array_from_query($query, 'id');
+
+        $subcat_ids = query2array($query,null, 'id');
         $subcat_ids[] = $page['category']['id'];
         $where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
@@ -326,5 +326,5 @@
 ;';
 
-    $page['items'] = array_from_query($query, 'image_id');
+    $page['items'] = query2array($query,null, 'image_id');
   }
 }
@@ -417,5 +417,5 @@
         $page,
         array(
-          'items' => array_from_query($query, 'image_id'),
+          'items' => query2array($query,null, 'image_id'),
           )
         );
@@ -464,5 +464,5 @@
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
                     .l10n('Recent photos').'</a>',
-        'items' => array_from_query($query, 'id'),
+        'items' => query2array($query,null, 'id'),
         )
       );
@@ -487,5 +487,5 @@
     $page['super_order_by'] = true;
     $conf['order_by'] = ' ORDER BY hit DESC, id DESC';
-    
+
     $query = '
 SELECT DISTINCT(id)
@@ -503,5 +503,5 @@
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
                     .$conf['top_number'].' '.l10n('Most visited').'</a>',
-        'items' => array_from_query($query, 'id'),
+        'items' => query2array($query,null, 'id'),
         )
       );
@@ -529,5 +529,5 @@
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
                     .$conf['top_number'].' '.l10n('Best rated').'</a>',
-        'items' => array_from_query($query, 'id'),
+        'items' => query2array($query,null, 'id'),
         )
       );
@@ -552,5 +552,5 @@
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
                     .l10n('Random photos').'</a>',
-        'items' => array_from_query($query, 'id'),
+        'items' => query2array($query,null, 'id'),
         )
       );
@@ -633,5 +633,5 @@
   {
     $redirect_url = script_basename()=='picture' ? duplicate_picture_url() : duplicate_index_url();
-    
+
     if (!headers_sent())
     { // this is a permanent redirection
