Nombre de photos à afficher selon l'id ??????

teler Messages postés 93 Statut Membre -  
teler Messages postés 93 Statut Membre -
Bonjour,
je travaille sur un site immobilier en php avec bdd mysql et je débute en php.

Ma question concerne l'affichage de photos selon une annonce immobiliere, selon l'annonce le nombre de photos afficher va varier.
Mais je ne sais pas comment m'y prendre pour faire ce code.

je pensais à une condition : si 3 champs textes photos ( dans la bdd) sont remplis alors il affiche 3 photos si , 2 champs sont remplis, il en affiche 2. etc etc

Voilà merci de m'aider
A voir également:

2 réponses

Nixial
 
Bonjour,

Hum tu fais une boucle, tu fais un select * from photos where id= "id_annonce".

Et ensuite tu fais une boucle et pour chaque occurence tu les affiche.

Du coup une annonce qui n'a que 2 photos en base ca va boucler 2 fois et tu en auras 2 voilà.

Bonne chance !
0
teler Messages postés 93 Statut Membre 5
 
Je ne suis pas sure d'avoir compris, en fait ,
voici mon code : sur ma première page, je fais une boucle while pour afficher toute les annonces selon ma recherche et j'affiche qu'une image pour chaque annonce.

$retour_messages=mysql_query('SELECT * FROM produits ORDER BY id DESC LIMIT '.$premiereEntree.', '.$messagesParPage.'');

while($data=mysql_fetch_assoc($retour_messages)) // On lit les entrées une à une grâce à une boucle
{

echo
'<div class="hautmarge"><img src="images/haut.png" /></div>
<div class="bas2"><div style="padding-bottom:20px"></div>
<form method="post" action="traitement.php" class="formulaire">
<table width="370" height="140">
<tr>
<td><div class="texteannonce">'.$data['type'].'</div></td>
<td></td>
</tr>
<tr>
<td>'.$data['nbre'].' pièces '.$data['surf'].' m2</td>
<td align="right">'.$data['prix'].' €</td>
</tr>

<tr>
<td><a href="annonce.php?ref='.$data['id'].' &prix='.$data['prix'].' &photo='.$data['photo'].' &photo2='.$data['photo2'].' &photo3='.$data['photo3'].'&photo4='.$data['photo4'].' &type='.$data['type'].' &surf='.$data['surf'].' &nbre='.$data['nbre'].' &description='.$data['description'].'">'.$data['description'].'</a></td>
<td align="right"> <a href="photos_annonces/'.$data['photo'].'" rel="shadowbox" title="'.$data['nbre'].' pièces, '.$data['surf'].' m2" >
<img height="100px" class="no_cadre" src="photos_annonces/' .$data['photo']. '"/></a></td>
</tr>
<tr><td></td><td align="right">réf : '.$data['id'].'</td></tr>
</table></form></div><div style="padding-bottom:20px"></div>';

}

il y a un lien sur la photo qui nous renvois sur une autre page , ( je fais passer toutes les infos dans le lien et je l'ai recupere sur ma page où il ya qu'une seule annonce par un $_GET pour afficher les spécificité du produit.

seulement là je lui demande d'afficher tout les champs de ma bdd, (j'ai creer 4 champs pour les noms des photos)

mais si il n'y a que 3 noms de photos, je vais avoir un icome image manquante.

Je n'ai surement pas bien proceder.

VOICI le code de la page qui recupere les infos par _GET :

<form class="formulaire">
<table width="370" height="236">
<TR height="10">
<TD></TD>
<TD></TD>
</TR>
<tr>
<td width="237"><div class="texteannonce"><?php echo $_GET['type'];?></div></td>
<td width="121"></td>
</tr>
<tr>
<td height="54"><?php echo $_GET['nbre'];?>
pièces
<?php echo $_GET['surf'];?> m2</td>
<td align="right"><?php echo $_GET['prix'];?> €</td>
</tr>
<tr>
<td valign="top"><?php echo $_GET['description']; ?> </td>
<td align="right" valign="top"><a href="photos_annonces/<?php echo $_GET['photo']; ?>" rel="shadowbox" title="<?php echo $_GET['nbre']; ?>pièces, <?php echo $_GET['surf']; ?> m2"><img src="photos_annonces/<?php echo $_GET['photo']; ?>" width="60px" class="no_cadre"/></a><a href="photos_annonces/<?php echo $_GET['photo']; ?>" rel="shadowbox" title="<?php echo $_GET['nbre']; ?>pièces, <?php echo $_GET['surf']; ?> m2"><img src="photos_annonces/<?php echo $_GET['photo']; ?>" width="60px" class="no_cadre"/></a><br />
<a href="photos_annonces/<?php echo $_GET['photo3']; ?>" rel="shadowbox" title="<?php echo $_GET['nbre']; ?>pièces, <?php echo $_GET['surf']; ?> m2"><img src="photos_annonces/<?php echo $_GET['photo']; ?>" width="60px" class="no_cadre"/></a><a href="photos_annonces/<?php echo $_GET['photo4']; ?>" rel="shadowbox" title="<?php echo $_GET['nbre']; ?>pièces, <?php echo $_GET['surf']; ?> m2"><img src="photos_annonces/<?php echo $_GET['photo']; ?>" width="60px" class="no_cadre"/></a><br />
<br />
réf : <?php echo $_GET['ref'];?></td>
</tr>
</table>
</form>
0