diff options
author | rvelices <rv-github@modusoptimus.com> | 2014-02-13 22:21:12 +0000 |
---|---|---|
committer | rvelices <rv-github@modusoptimus.com> | 2014-02-13 22:21:12 +0000 |
commit | 2b81fbc4aa00ab4fcef794083c3f8e2d6bfe314e (patch) | |
tree | 08dae87951f3b196063d30fbae5b1fb12c441c87 /include | |
parent | d0733822cebce4c1314ee3e70e4e5ce84df98640 (diff) |
more query2array
git-svn-id: http://piwigo.org/svn/trunk@27369 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r-- | include/calendar_base.class.php | 4 | ||||
-rw-r--r-- | include/category_default.inc.php | 2 | ||||
-rw-r--r-- | include/functions.inc.php | 32 | ||||
-rw-r--r-- | include/functions_category.inc.php | 6 | ||||
-rw-r--r-- | include/functions_html.inc.php | 2 | ||||
-rw-r--r-- | include/functions_notification.inc.php | 8 |
6 files changed, 15 insertions, 39 deletions
diff --git a/include/calendar_base.class.php b/include/calendar_base.class.php index ac2d33ce2..f48fae1e3 100644 --- a/include/calendar_base.class.php +++ b/include/calendar_base.class.php @@ -246,7 +246,7 @@ $this->inner_sql. $this->get_date_where($level).' GROUP BY period;'; - $level_items = simple_hash_from_query($query, 'period', 'nb_images'); + $level_items = query2array($query, 'period', 'nb_images'); if ( count($level_items)==1 and count($page['chronology_date'])<count($this->calendar_levels)-1) @@ -317,7 +317,7 @@ AND ' . $this->date_field . ' IS NOT NULL GROUP BY period'; $current = implode('-', $page['chronology_date'] ); - $upper_items = array_from_query( $query, 'period'); + $upper_items = query2array($query,null, 'period'); usort($upper_items, 'version_compare'); $upper_items_rank = array_flip($upper_items); diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 59f2195b0..192fcb7d2 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -84,7 +84,7 @@ SELECT image_id, COUNT(*) AS nb_comments AND image_id IN ('.implode(',', $selection).') GROUP BY image_id ;'; - $nb_comments_of = simple_hash_from_query($query, 'image_id', 'nb_comments'); + $nb_comments_of = query2array($query, 'image_id', 'nb_comments'); } } diff --git a/include/functions.inc.php b/include/functions.inc.php index d163a2725..d81d62727 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1253,15 +1253,7 @@ function prepend_append_array_items($array, $prepend_str, $append_str) */ function simple_hash_from_query($query, $keyname, $valuename) { - $array = array(); - - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $array[ $row[$keyname] ] = $row[$valuename]; - } - - return $array; + return query2array($query, $keyname, $valuename); } /** @@ -1275,13 +1267,7 @@ function simple_hash_from_query($query, $keyname, $valuename) */ function hash_from_query($query, $keyname) { - $array = array(); - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $array[ $row[$keyname] ] = $row; - } - return $array; + return query2array($query, $keyname); } /** @@ -1296,24 +1282,14 @@ function hash_from_query($query, $keyname) */ function array_from_query($query, $fieldname=false) { - $array = array(); - - $result = pwg_query($query); if (false === $fieldname) { - while ($row = pwg_db_fetch_assoc($result)) - { - $array[] = $row; - } + return query2array($query); } else { - while ($row = pwg_db_fetch_assoc($result)) - { - $array[] = $row[$fieldname]; - } + return query2array($query, null, $fieldname); } - return $array; } /** diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 43289ca01..f22e529dd 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -205,7 +205,7 @@ SELECT * FROM '.CATEGORIES_TABLE.' WHERE id IN ('.$cat['uppercats'].') ;'; - $names = hash_from_query($query, 'id'); + $names = query2array($query, 'id'); // category names must be in the same order than uppercats list $cat['upper_names'] = array(); @@ -302,7 +302,7 @@ function display_select_cat_wrapper($query, $blockname, $fullname = true) { - $categories = array_from_query($query); + $categories = query2array($query); usort($categories, 'global_rank_compare'); display_select_categories($categories, $selecteds, $blockname, $fullname); } @@ -362,7 +362,7 @@ SELECT id, permalink, 0 AS is_old FROM '.CATEGORIES_TABLE.' WHERE permalink IN ('.$in.') ;'; - $perma_hash = hash_from_query($query, 'permalink'); + $perma_hash = query2array($query, 'permalink'); if ( empty($perma_hash) ) return null; diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 8cad4e395..6852e48d2 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -113,7 +113,7 @@ function get_cat_display_name_cache($uppercats, SELECT id, name, permalink FROM '.CATEGORIES_TABLE.' ;'; - $cache['cat_names'] = hash_from_query($query, 'id'); + $cache['cat_names'] = query2array($query, 'id'); } $output = ''; diff --git a/include/functions_notification.inc.php b/include/functions_notification.inc.php index af46f50d2..623369915 100644 --- a/include/functions_notification.inc.php +++ b/include/functions_notification.inc.php @@ -217,7 +217,7 @@ function custom_notification_query($action, $type, $start=null, $end=null) break; } $query = 'SELECT DISTINCT '.$field_id.' '.$query.';'; - $infos = array_from_query($query); + $infos = query2array($query); return $infos; break; } @@ -456,7 +456,7 @@ SELECT ORDER BY date_available DESC LIMIT '.$max_dates.' ;'; - $dates = array_from_query($query); + $dates = query2array($query); for ($i=0; $i<count($dates); $i++) { @@ -471,7 +471,7 @@ SELECT DISTINCT i.* ORDER BY '.DB_RANDOM_FUNCTION.'() LIMIT '.$max_elements.' ;'; - $dates[$i]['elements'] = array_from_query($query); + $dates[$i]['elements'] = query2array($query); } if ($max_cats>0) @@ -489,7 +489,7 @@ SELECT ORDER BY img_count DESC LIMIT '.$max_cats.' ;'; - $dates[$i]['categories'] = array_from_query($query); + $dates[$i]['categories'] = query2array($query); } } |