Ignore:
Timestamp:
Sep 19, 2003, 11:40:52 PM (21 years ago)
Author:
z0rglub
Message:

A category can have its representative picture

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r68 r133  
    292292
    293293// update_category updates calculated informations about a category :
    294 // date_last and nb_images
     294// date_last and nb_images. It also verifies that the representative picture
     295// is really linked to the category.
    295296function update_category( $id = 'all' )
    296297{
     
    334335    $query.= ';';
    335336    mysql_query( $query );
     337    // updating the representative_picture_id : if the representative
     338    // picture of the category is not any more linked to the category, we
     339    // have to set representative_picture_id to NULL
     340    $query = 'SELECT representative_picture_id';
     341    $query.= ' FROM '.PREFIX_TABLE.'categories';
     342    $query.= ' WHERE id = '.$id;
     343    $row = mysql_fetch_array( mysql_query( $query ) );
     344    // if the category has no representative picture (ie
     345    // representative_picture_id == NULL) we don't update anything
     346    if ( $row['representative_picture_id'] != '' )
     347    {
     348      $query = 'SELECT image_id';
     349      $query.= ' FROM '.PREFIX_TABLE.'image_category';
     350      $query.= ' WHERE category_id = '.$id;
     351      $query.= ' AND image_id = '.$row['representative_picture_id'];
     352      $query.= ';';
     353      $result = mysql_query( $query );
     354      if ( mysql_num_rows( $result ) == 0 )
     355      {
     356        $query = 'UPDATE '.PREFIX_TABLE.'categories';
     357        $query.= ' SET representative_picture_id = NULL';
     358        $query.= ' WHERE id = '.$id;
     359        $query.= ';';
     360        mysql_query( $query );
     361      }
     362    }
    336363  }
    337364}
Note: See TracChangeset for help on using the changeset viewer.