<?php
$nb = 3; // Nombre d'affichages souhaités sur une ligne
// requête SQL
$sql = "SELECT * FROM `photosnap` ORDER BY `id` DESC";
// envoie de la requête
$req = mysql_query($sql) or die('<u>Probleme SQL</u> : '.$sql.'<br>'.mysql_error
());
// affichage des résultats avec $nb résultats par ligne
echo'<table>';
$i = 1;
while($resultat = mysql_fetch_array($req)) {
if($i == 1) { echo'<tr>'; }
echo'<td align="center">
<div id="cadresnap">
<img src="../snap/' , $resultat['photo'] , '" /></br>
' , $resultat['prenom'] , '</br>
>/div>
</td>';
$i++;
if($i > $nb) { echo'</tr>'; $i = 1; }
}
echo'</table>';
?>
<form action="photo-snap-valide.php" method="post" enctype="multipart/form-data">
<p> </p>
<table border="0" cellspacing="10" cellpadding="0">
<tr>
<td><div align="right">Nom </div></td>
<td><input type="text" name="nom" /></td>
</tr>
<tr>
<td>Commentaire</td>
<td><textarea name="commentaire" id="commentaire" maxlength="255"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Valider" /></td>
</tr>
</table>
</form>
ma page de validation du commentaire: photo-snap-valide.php<?PHP
$sql = "INSERT INTO photosnapcom(id, nom, commentaire)
VALUES('','$nom','$commentaire')";
mysql_query($sql)
or die('Erreur SQL !'.$sql.'
'.mysql_error());
echo 'Votre commentaire a été ajouter.';
mysql_close();
?> $sql = "SELECT a.*,b.nom,b.commentaire FROM `photosnap` AS a LEFT JOIN `photosnapcom` AS b ON a.id = b.id ORDER BY `a.id` DESC";
//il faut ensuite que tu récupéres $resultat['id'] dans le formulaire de commentaire. $sql = "SELECT a.*,b.nom,b.commentaire FROM `photosnap` AS a LEFT JOIN `photosnapcom` AS b ON a.id = b.id WHERE `a.id`= "ID" \\ => ID DE LA PHOTO AFFICHER";
a.* correspond a la table `photosnap`echo'<td align="center">
<div id="cadresnap">
<img src="../snap/' , $resultat['photo'] , '"/></br>
' , $resultat['prenom'] , '</br>
' , $resultat['date'] , '</br>
<a href=\'photo-snap-com.php?id=' .$resultat->id.'\'>ajouter un commentaire</a>
</div> Code : Tout sélectionner
<a href=\'photo-snap-com.php?id=' .$resultat['id'].'\'>ajouter un commentaire</a>Code : Tout sélectionner
<form action="photo-snap-valide.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id_photo" value="<?php echo $id; ?>">
<p> </p>
<table border="0" cellspacing="10" cellpadding="0">
<tr>
<td><div align="right">Nom </div></td>
<td><input type="text" name="nom" /></td>
</tr>
<tr>
<td>Commentaire</td>
<td><textarea name="commentaire" id="commentaire" maxlength="255"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="submit" type="submit" value="Valider" /></td>
</tr>
</table>
</form> Code : Tout sélectionner
Erreur SQL !INSERT INTO photosnapcom(id, nom, commentaire) VALUES('22','fabrice','essai commentaire numero 2') Duplicate entry '22' for key 1Code : Tout sélectionner
CREATE TABLE `photosnapcom` (
`pid` mediumint(75) NOT NULL auto_increment,
`id` mediumint(75),
nom varchar(128) NOT NULL default '',
commentaire text NOT NULL,
PRIMARY KEY (`pid`)
); <?php
$nb = 3; // Nombre d'affichages souhaités sur une ligne
// requête SQL
$sql = "SELECT *, DATE_FORMAT(date,'%d/%m/%Y - %H:%i') as date FROM `photosnap` ORDER BY `id` DESC";
// envoie de la requête
$req = mysql_query($sql) or die('<u>Probleme SQL</u> : '.$sql.'<br>'.mysql_error
());
// affichage des résultats avec $nb résultats par ligne
echo'<table>';
$i = 1;
while($resultat = mysql_fetch_array($req)) {
if($i == 1) { echo'<tr>'; }
echo'<td align="center">
<div id="cadresnap">' , $resultat['prenom'] , '
<img src="../snap/' , $resultat['photo'] , '" alt="' , $resultat['prenom'] , ' a mis sa trombine sur photos vosges" /></br>
<div class="com" id="com">
<a href="photo-snap-com.php?id=' , $resultat['id'] , '" style="color: #FF9900; text-decoration: none;" onclick="window.open(\'\',\'popup\',\'width=400,top=0,left=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0\')" target="popup"> <img src="../images/com.png" alt="ajouter un commentaire" border="0"></a>
</div>
<div class="date">' , $resultat['date'] , ' </div>
</div>
</td>';
$i++;
if($i > $nb) { echo'</tr>'; $i = 1; }
}
echo'</table>';
?>
// j'affiche le nombre total des commentaires stockés dans la table photosnapcom.
<?PHP
$data = mysql_query("SELECT count(idcom) FROM photosnapcom");
$donnees = mysql_fetch_array($data);
$nbr = $donnees[0];
echo $donnees['0'].' commentaires ont été poster dans cette galerie';
?>