Annonce

  •  » Utilisation
  •  » afficher nom de la catégorie dans random.php

#1 2004-10-07 13:21:02

dimdim
Membre
Le Roeulx (Belgique)
2004-08-10
13

afficher nom de la catégorie dans random.php

dans ma page random.php, je voudrais afficher le nom de la catégorie au dessus de la photo aléatoire. Pour l'instant je ne suis parvenu quà afficher l'auteur et l'id de la catégorie, mais pas le nom...

voilà mon code:

Code:


<?php
/***************************************************************************
 *                                 random.php                              *
 *                            -------------------                          *
 *   application   : PhpWebGallery 1.3 <http://phpwebgallery.net>          *
 *   author        : Pierrick LE GALL <pierrick@z0rglub.com>               *
 *                                                                         *
 *   $Id: random.php,v 1.1.1.1 2003/11/01 10:31:53 z0rglub Exp $
 *                                                                         *
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation;                                         *
 *                                                                         *
 ***************************************************************************/

//--------------------------------------------------------------- configuration
define( PREFIX_INCLUDE, 'photos/' ); // relative path to your gallery
define( USER_ID, 2 ); // 2 is the guest, 1 the webmaster
//-------------------------------------------------------------------- includes
include( PREFIX_INCLUDE.'include/functions.inc.php' );
database_connection();
//-------------------------------------------------- configuraiton informations
$query = 'SELECT prefix_thumbnail';
$query.= ' FROM '.PREFIX_TABLE.'config';
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
$prefix_thumbnail = $row['prefix_thumbnail'];
//----------------------------------------------------------- user informations
$query = 'SELECT status';
$query.= ' FROM '.PREFIX_TABLE.'users';
$query.= ' WHERE id = '.USER_ID;
$query.= ';';
$row = mysql_fetch_array( mysql_query( $query ) );
$user_status = $row['status'];


//-----------------fonction enlev&eacute;e--------$restricted_cats = get_all_restrictions( USER_ID, $user_status );
//------------------------------------------------------------- which picture ?
$query = 'SELECT id,file,author,storage_category_id,tn_ext,category_id';
$query.= ' FROM '.PREFIX_TABLE.'images';
$query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category AS ic ON id = ic.image_id';
if ( count( $restricted_cats ) > 0 )
{
  $query.= ' WHERE category_id NOT IN (';
  foreach ( $restricted_cats as $i => $restricted_cat ) {
    if ( $i > 0 ) $query.= ',';
    $query.= $restricted_cat;
  }
  $query.= ')';
}
$query.= ' ORDER BY RAND()';
$query.= ' LIMIT 0,1';
$query.= ';';

$result = mysql_query( $query );
$row = mysql_fetch_array( $result );




// create directory where the thumbnail can be found
$site_url = get_site_url( $row['storage_category_id'] );
if ( $site_url == './galleries/' ) $site_url = PREFIX_INCLUDE.'galleries/';
$cat_directory = $site_url.get_local_dir( $row['storage_category_id'] );
// file to display
$file = get_filename_wo_extension( $row['file'] );
// URL of the thumbnail
$thumb_url = $cat_directory.'thumbnail/';
$thumb_url.= $prefix_thumbnail.$file.'.'.$row['tn_ext'];
// link to the gallery
$thumb_link = PREFIX_INCLUDE.'picture.php';
$thumb_link.= '?cat='.$row['category_id'];
$thumb_link.= '&amp;image_id='.$row['id'];

// afficher id catégorie
$id_categorie = $row['storage_category_id'];

// afficher auteur
  $auteur = 'Photographe: <b>'.$row['author'].'</b>';

//------------------------------------------------------------- display picture
echo ''.$id_categorie;
echo '<a href="'.$thumb_link.'" target="_blank">';
echo '<div align="center"><img src="'.$thumb_url.'" alt="" style="border:1px solid black;"/><div>';
echo '</a>';
echo ''.$auteur ;
  
?>

Quelqu'un pourrait modifier mon code de manière à remplacer l'affichage de l'id de la catégorie (pas très intéressant comme info à afficher !) par le nom de cette catégorie ?

Merci d'avance !


- dim -

Hors ligne

#2 2004-12-30 17:48:05

sixprod
Membre
2004-08-07
118

Re: afficher nom de la catégorie dans random.php

Bonjour,
le lien entre id et nom se trouve dans la table categories
id et name y sont
Je cherche aussi, mais si ça peut m'aider ce serait bien
voir mon post
http://forum.phpwebgallery.net/viewtopic.php?id=2913

Hors ligne

  •  » Utilisation
  •  » afficher nom de la catégorie dans random.php

Pied de page des forums

Propulsé par FluxBB

github twitter newsletter Faire un don Piwigo.org © 2002-2024 · Contact