Note that there are some explanatory texts on larger screens.

plurals
  1. POCommenting on a comment
    text
    copied!<p>I'm currently working on a commenting system, and I want to let users to comment on an existent comment.</p> <p>I created a link for each comment to be able to click on it to be redirected to the form to write an answer to an existent comment. When the form will be submitted, a hidden input should take to current id of the existent comment. But there is a problem: the id of each comment is available in a while loop but as soon as the loop is done, the variable disappears. So I would like to know how to get the id of each comment to send it in a hidden input.</p> <p>Here my full code:</p> <pre><code>&lt;h2&gt;Fiche&lt;/h2&gt; &lt;?php $_SESSION['cf']['message'] = $_GET['message']; $reponse = db_query('SELECT * FROM messages WHERE id = ?', array($_SESSION['cf']['message'])); $donneesmsg = $reponse-&gt;fetch() ?&gt; &lt;h5&gt;&lt;?php echo $donneesmsg['Pseudo']; ?&gt;&lt;/h5&gt; &lt;p class="text-center text-align"&gt;&lt;?php echo $donneesmsg['Message']; ?&gt;&lt;/p&gt; &lt;a href="index.php?page=fiche&amp;message=&lt;?php echo $_SESSION['cf']['message'] ?&gt;&amp;#formcom"&gt;Repondre&lt;/a&gt; &lt;?php echo '&lt;h4&gt;Commentaires&lt;/h4&gt;'; echo '&lt;hr&gt;'; $reponse1 = db_query('SELECT * FROM comment WHERE messages_id = ?', array($donneesmsg['id'])); $donneescom1 = $reponse1-&gt;fetch(); $reponse = db_query('SELECT * FROM comment WHERE messages_id = ? ORDER BY id ASC', array($donneesmsg['id'])); while ($donneescom = $reponse-&gt;fetch()) { if ($donneescom['commentaires_id'] == 0) { echo '&lt;center&gt;'; echo '' .$donneescom['id']. '&lt;br&gt;'; echo '' .$donneescom['pseudo']. '&lt;br&gt;'; echo '' .$donneescom['commentaire']. '&lt;br&gt;'; echo '&lt;a href="index.php?page=fiche&amp;message=' .$_SESSION['cf']['message']. '&amp;com=' .$donneescom['id']. '#formcom"&gt;Repondre&lt;/a&gt;'; echo '&lt;hr&gt;'; echo '&lt;/center&gt;'; } if ($donneescom['commentaires_id'] != 0) { echo 'En reponse au com ' .$donneescom['commentaires_id']. '&lt;br&gt;'; echo '' .$donneescom['id']. '&lt;br&gt;'; echo '' .$donneescom['pseudo']. '&lt;br&gt;'; echo '' .$donneescom['commentaire']. '&lt;br&gt;'; echo '&lt;a href="index.php?page=fiche&amp;message=' .$_SESSION['cf']['message']. '&amp;com=' .$donneescom['id']. '#formcom"&gt;Repondre&lt;/a&gt;'; echo '&lt;hr&gt;'; } } $reponse1 = db_query('SELECT * FROM comment WHERE messages_id = ?', array($donneesmsg['id'])); $donneescom1 = $reponse1-&gt;fetch(); ?&gt; &lt;form id="formcom" method="post" action="index.php?page=addcomment"&gt; Pseudo: &lt;input type="text" placeholder="Pseudo" name="pseudo"&gt; &lt;br&gt; Mail: &lt;input type="email" placeholder="Mail" name="mail"&gt; &lt;br&gt; Commentaire: &lt;textarea placeholder="Commentaire" name="commentaire"&gt;&lt;/textarea&gt; &lt;br&gt; &lt;input type="hidden" name="date" value="&lt;?php echo time(); ?&gt;"&gt;&lt;br&gt; &lt;input type="hidden" name="messages_id" value="&lt;?php echo $donneesmsg['id']; ?&gt;"&gt;&lt;br&gt; &lt;input type="text" name="commentaires_id" value="&lt;?php echo $donneescom1['id']; ?&gt;"&gt;&lt;br&gt; &lt;input type="hidden" name="id" value="&lt;?php echo $donneesmsg['id']; ?&gt;"&gt;&lt;br&gt; &lt;input type="submit" value="Envoyer"&gt; &lt;/form&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload