Ignore:
Timestamp:
Jul 6, 2008, 12:13:28 AM (16 years ago)
Author:
rvelices
Message:
  • feature 832: Folders with no images sql optimization
  • recent pics are sorted by date descending, and only then by conforder_by
  • updated prototype.js to version 1.6
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_cats.inc.php

    r2330 r2424  
    8989  else if ($conf['allow_random_representative'])
    9090  {// searching a random representant among elements in sub-categories
    91     $query = '
     91    if ($row['count_images']>0)
     92    {
     93      $query = '
    9294SELECT image_id
    9395  FROM '.CATEGORIES_TABLE.' AS c INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic
    9496    ON ic.category_id = c.id';
    95     $query.= '
     97      $query.= '
    9698  WHERE (c.id='.$row['id'].' OR uppercats LIKE \''.$row['uppercats'].',%\')'
    97   .get_sql_condition_FandF
    98   (
    99     array
    100       (
    101         'forbidden_categories' => 'c.id',
    102         'visible_categories' => 'c.id',
    103         'visible_images' => 'image_id'
    104       ),
    105     "\n  AND"
    106   ).'
     99    .get_sql_condition_FandF
     100    (
     101      array
     102        (
     103          'forbidden_categories' => 'c.id',
     104          'visible_categories' => 'c.id',
     105          'visible_images' => 'image_id'
     106        ),
     107      "\n  AND"
     108    ).'
    107109  ORDER BY RAND()
    108110  LIMIT 0,1
    109111;';
    110     $subresult = pwg_query($query);
    111     if (mysql_num_rows($subresult) > 0)
    112     {
    113       list($image_id) = mysql_fetch_row($subresult);
     112      $subresult = pwg_query($query);
     113      if (mysql_num_rows($subresult) > 0)
     114      {
     115        list($image_id) = mysql_fetch_row($subresult);
     116      }
    114117    }
    115118  }
    116119  else
    117120  { // searching a random representant among representant of sub-categories
    118     $query = '
    119 SELECT representative_picture_id
    120   FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
    121   ON id = cat_id and user_id = '.$user['id'].'
    122   WHERE uppercats LIKE \''.$row['uppercats'].',%\'
    123     AND representative_picture_id IS NOT NULL'
    124   .get_sql_condition_FandF
    125   (
    126     array
    127       (
    128         'visible_categories' => 'id',
    129       ),
    130     "\n  AND"
    131   ).'
    132   ORDER BY RAND()
    133   LIMIT 0,1
    134 ;';
    135     $subresult = pwg_query($query);
    136     if (mysql_num_rows($subresult) > 0)
    137     {
    138       list($image_id) = mysql_fetch_row($subresult);
     121    if ($row['count_categories']>0 and $row['count_images']>0)
     122    {
     123      $query = '
     124  SELECT representative_picture_id
     125    FROM '.CATEGORIES_TABLE.' INNER JOIN '.USER_CACHE_CATEGORIES_TABLE.'
     126    ON id = cat_id and user_id = '.$user['id'].'
     127    WHERE uppercats LIKE \''.$row['uppercats'].',%\'
     128      AND representative_picture_id IS NOT NULL'
     129    .get_sql_condition_FandF
     130    (
     131      array
     132        (
     133          'visible_categories' => 'id',
     134        ),
     135      "\n  AND"
     136    ).'
     137    ORDER BY RAND()
     138    LIMIT 0,1
     139  ;';
     140      $subresult = pwg_query($query);
     141      if (mysql_num_rows($subresult) > 0)
     142      {
     143        list($image_id) = mysql_fetch_row($subresult);
     144      }
    139145    }
    140146  }
Note: See TracChangeset for help on using the changeset viewer.