Ignore:
Timestamp:
Sep 6, 2003, 9:22:59 AM (21 years ago)
Author:
z0rglub
Message:
  • Creation of plain structure if not existing in several functions
  • Change in SQL request about restrictions : using "AND category_id NOT IN (x,y,z)" instead of "AND category_id != x AND category_id != y AND category_id != z"
  • For search and most recent category, using "COUNT(DISTINCT(id))" instead of "COUNT(*)" and using JOIN with image_category table
File:
1 edited

Legend:

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

    r64 r67  
    128128{
    129129  global $page;
     130
     131  if ( !isset( $page['plain_structure'] ) )
     132    $page['plain_structure'] = get_plain_structure();
    130133
    131134  $structure = array();
     
    303306
    304307  $cat['name'] = array();
     308
     309  if ( !isset( $page['plain_structure'] ) )
     310    $page['plain_structure'] = get_plain_structure();
     311
    305312  array_push( $cat['name'], $page['plain_structure'][$id]['name'] );
    306313  while ( $page['plain_structure'][$id]['id_uppercat'] != '' )
     
    330337  global $page;
    331338
     339  if ( !isset( $page['plain_structure'] ) )
     340    $page['plain_structure'] = get_plain_structure();
     341 
    332342  // creating the local path : "root_cat/sub_cat/sub_sub_cat/"
    333343  $dir = $page['plain_structure'][$category_id]['dir'].'/';
     
    345355{
    346356  global $page;
     357
     358  if ( !isset( $page['plain_structure'] ) )
     359    $page['plain_structure'] = get_plain_structure();
    347360
    348361  $query = 'SELECT galleries_url';
     
    434447        // we must not show pictures of a forbidden category
    435448        $restricted_cats = get_all_restrictions( $user['id'],$user['status'] );
    436         foreach ( $restricted_cats as $restricted_cat ) {
    437           $where_append.= ' AND category_id != '.$restricted_cat;
     449        if ( count( $restricted_cats ) > 0 )
     450        {
     451          $where_append.= ' AND category_id NOT IN (';
     452          foreach ( $restricted_cats as $i => $restricted_cat ) {
     453            if ( $i > 0 ) $where_append.= ',';
     454            $where_append.= $restricted_cat;
     455          }
     456          $where_append.= ')';
    438457        }
    439458      }
     
    482501        $page['where'].= $where_append;
    483502
    484         $query = 'SELECT COUNT(*) AS nb_total_images';
     503        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
    485504        $query.= ' FROM '.PREFIX_TABLE.'images';
     505        $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
     506        $query.= ' ON id = ic.image_id';
    486507        $query.= $page['where'];
    487508        $query.= ';';
     
    514535        $page['where'].= $where_append;
    515536
    516         $query = 'SELECT COUNT(*) AS nb_total_images';
     537        $query = 'SELECT COUNT(DISTINCT(id)) AS nb_total_images';
    517538        $query.= ' FROM '.PREFIX_TABLE.'images';
     539        $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic';
     540        $query.= ' ON id = ic.image_id';
    518541        $query.= $page['where'];
    519542        $query.= ';';
     
    531554        }
    532555      }
    533      
     556
    534557      if ( $query != '' )
    535558      {
     559        echo $query;
    536560        $result = mysql_query( $query );
    537561        $row = mysql_fetch_array( $result );
Note: See TracChangeset for help on using the changeset viewer.