Affichage de photo en tableau

Résolu
Bonjour, à tous

voila, je suis en php 5 + easyphp.
je construit une photothèque et j'ai un problème pour afficher mes images dans un tableau. je m'explique:

j'ai réalisé une page avec un moteur de recherche interne- il fonctionne, je tape un mot-clés ex="lavande" et toutes les photos de lavande s'affichent. oui mais, elles s'affichent les unes en dessous des autres, et je voudrais les voir en grille..

je n'arrive pas à trouver à faire un code pour les afficher !
si quelqu'un à un bout de code il serait le bien venu et grand merci d'avance A+

voila le code

<?php require_once('Connections/connexiontoto.php'); ?>
<?php
$maxRows_Recherche_1 = 10;
$pageNum_Recherche_1 = 0;
if (isset($_GET['pageNum_Recherche_1'])) {
$pageNum_Recherche_1 = $_GET['pageNum_Recherche_1'];
}
$startRow_Recherche_1 = $pageNum_Recherche_1 * $maxRows_Recherche_1;

$colname1_Recherche_1 = "0";
if (isset($_POST['search'])) {
$colname1_Recherche_1 = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
}
$colname_Recherche_1 = "0";
if (isset($_POST['search'])) {
$colname_Recherche_1 = (get_magic_quotes_gpc()) ? $_POST['search'] : addslashes($_POST['search']);
}
mysql_select_db($database_connexiontoto, $connexiontoto);
$query_Recherche_1 = sprintf("SELECT numero, photo, motcles FROM recherche WHERE numero LIKE '%%%s%%' OR motcles LIKE '%%%s%%' ORDER BY recherche.numero ASC", $colname_Recherche_1,$colname1_Recherche_1);
$query_limit_Recherche_1 = sprintf("%s LIMIT %d, %d", $query_Recherche_1, $startRow_Recherche_1, $maxRows_Recherche_1);
$Recherche_1 = mysql_query($query_limit_Recherche_1, $connexiontoto) or die(mysql_error());
$row_Recherche_1 = mysql_fetch_assoc($Recherche_1);

if (isset($_GET['totalRows_Recherche_1'])) {
$totalRows_Recherche_1 = $_GET['totalRows_Recherche_1'];
} else {
$all_Recherche_1 = mysql_query($query_Recherche_1);
$totalRows_Recherche_1 = mysql_num_rows($all_Recherche_1);
}
$totalPages_Recherche_1 = ceil($totalRows_Recherche_1/$maxRows_Recherche_1)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Document sans titre</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php
//TEV Search Result Recherche_1
$balise = '';
$fin_balise = '';
$search = $_POST['search'];
if(empty($search))
{
echo htmlentities("Erreur ! Le champ de recherche est vide.");
exit();
}
elseif ($totalRows_Recherche_1 == 1)
{ echo ''.$totalRows_Recherche_1.' '.htmlentities("enregistrement trouvé pour votre requête :").' '.$balise.''.$_POST['search'].''.$fin_balise.'';
}
elseif ($totalRows_Recherche_1 >1)
{ echo ''.$totalRows_Recherche_1.' '.htmlentities("enregistrements trouvés pour votre requête :").' '.$balise.''.$_POST['search'].''.$fin_balise.'';
}
else
{ echo ''.htmlentities("aucun enregistrement trouvé pour votre requête :").' '.$balise.''.$_POST['search'].''.$fin_balise.'';
}
?>
<?php do { ?>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><img src="../Photos/<?php echo $row_Recherche_1['photo']; ?>" alt="" /></td>
<td> </td>
<td> </td>
</tr>
<tr>
<td><?php echo $row_Recherche_1['numero']; ?></td>
<td> </td>
<td> </td>
</tr>
</table>
<?php } while ($row_Recherche_1 = mysql_fetch_assoc($Recherche_1)); ?>
</body>
</html>
<?php
mysql_free_result($Recherche_1);
?>
Configuration: Windows XP
Firefox 2.0.0.11

3 réponses

  1. Contributeur
    Bonsoir,

    Voici un code source avec un mélange de php et de html qui affiche des photos dans un tableau à toi de l'adapter avec ton script.

    <table align='center' border='1' cellspacing='1' cellpadding='1' width='800px'>
    <tr>
    <?php
    //initialisation du compteur
    $compteur = 0;

    while ($compteur < 15)
    {
    if ( $compteur % 5 != 0 ) // 5 photos seront affichés sur 3 lignes
    {
    ?>
    <td><img src='image.jpg' border='0' width='120px'></td>
    <?php
    }
    else
    {
    ?>
    </tr><tr><td><img src='image.jpg' border='0' width='120px'></td>
    <?php
    }
    $compteur = $compteur + 1;
    }
    ?>
    </tr>
    </table>

    @+
    0
    1. merci, je vais essayer de l'adapter a +
      0
    2. ok ça marche, mais images s'affichent en grille. le nouveau soucis c'est que j'en est 15 de la même!! faut je voie pour en afficher une à la fois mantenant..
      0
  2. Contributeur
    Bonjour,

    Eh bien oui il faut maintenant faire ta requete SQL qui va aller chercher tes photos la ou il faut.
    en utilisant la boucle while pour afficher les photos tant qu'il y en a.

    @+
    0
    1. en ce lundi j'ai trouvé!
      salut rescue, ma requête sql fonctionnais normalement, en faite le tableau se multipliais et les images aussi donc merci pour ton aide encore
      0