Salut
Je voudrais faire une galerie photo à partir d'une base MySql grâce à la fonction do{} while{};.
Mais je ne sais pas comment faire une saut de ligne tous les 5 images par exemple.
Merci
<?php
$cnx = mysql_connect( "localhost", "root", "" ) or die ("Impossible de se connecter au serveur") ;
mysql_select_db('photos',$cnx);
$query_galphoto = "SELECT photos.url, photos.id FROM photos";
$galphoto = mysql_query($query_galphoto, $cnx) or die(mysql_error());
$row_galphoto = mysql_fetch_assoc($galphoto);
$totalRows_galphoto = mysql_num_rows($galphoto);
?>
<?php
$i = 0;
while(($row_galphoto= mysql_fetch_assoc($galphoto)) != false)
{
if($i % 5 == 0)
{
echo "<p>";
}
?>
<a href="<?php echo $row_galphoto['url'];?>">
<img src="<?php echo $row_galphoto['id'];?>" width="150" alt="<?php echo $row_galphoto['id'];?>">
</a>
<?php
$i++;
};
?>
j'ai une base de donnés appelée photos, et une table photos qui contient 2 champs url et id<?php
$cnx = mysql_connect( "localhost", "root", "" ) or die ("Impossible de se connecter au serveur") ;
mysql_select_db('photos',$cnx);
$query_galphoto = "SELECT photos.url, photos.id FROM photos";
$galphoto = mysql_query($query_galphoto, $cnx) or die(mysql_error());
$row_galphoto = mysql_fetch_assoc($galphoto);
$totalRows_galphoto = mysql_num_rows($galphoto);
?>
<?php
$i = 0;
while(($row_galphoto= mysql_fetch_assoc($galphoto)) != false)
{
echo (($i % 5) == 0) ? "<p>" : null;
?>
<a href="<?php echo $row_galphoto['url'];?>"><img src="<?php echo $row_galphoto['id'];?>" width="150" alt="<?php echo $row_galphoto['id'];?>"></a>
<?php
echo (($i % 5) == 0) ? "</p>\n" : null;
$i++;
};
?>
Éventuellement, fais afficher ta page et de là, affiche le code source généré pour vérifier si tout a l'air normal, on trouve des choses étranges des fois Code : Tout sélectionner
<?php
$i = 0;
do
{
if($i % 5 == 0)
{
echo "<p>";
}
?>
<a href="<?php echo $row_galphoto['url'];?>">
<img src="<?php echo $row_galphoto['id'];?>" width="150" alt="<?php echo $row_galphoto['id'];?>">
</a>
<?php
$i++;
}
while(($row_galphoto= mysql_fetch_assoc($galphoto)) != false);
?>