From f95f48a226118dd541130e2cec8e18fd13bff128 Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 25 Apr 2008 23:39:06 +0000 Subject: - merge r2308 and r2309 from trunk to branch-1_7 - minor mysql query optimizations - less mysql queries on the picture page (under some circumstances) git-svn-id: http://piwigo.org/svn/branches/branch-1_7@2310 68402e56-0260-453c-a942-63ccdbb3a9ee --- include/picture_rate.inc.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'include/picture_rate.inc.php') diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php index 331cb41b0..f2410945b 100644 --- a/include/picture_rate.inc.php +++ b/include/picture_rate.inc.php @@ -32,14 +32,22 @@ if ($conf['rate']) { - $query = ' + if ( NULL != $picture['current']['average_rate'] ) + { + $query = ' SELECT COUNT(rate) AS count , ROUND(AVG(rate),2) AS average , ROUND(STD(rate),2) AS STD FROM '.RATE_TABLE.' WHERE element_id = '.$picture['current']['id'].' ;'; - $row = mysql_fetch_array(pwg_query($query)); + $row = mysql_fetch_array(pwg_query($query)); + } + else + { // avg rate null -> no rate -> no need to query db + $row = array( 'count'=>0, 'average'=>NULL, 'std'=>NULL ); + } + if ($row['count'] == 0) { $value = l10n('no_rate'); -- cgit v1.2.3