<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: aaronesteban1</title>
    <description>The latest articles on DEV Community by aaronesteban1 (@aaronesteban1).</description>
    <link>https://dev.to/aaronesteban1</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F281823%2Fff08e29d-5a7d-4acd-8e06-b789ca24f725.png</url>
      <title>DEV Community: aaronesteban1</title>
      <link>https://dev.to/aaronesteban1</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/aaronesteban1"/>
    <language>en</language>
    <item>
      <title>PHP Comment System With Replies</title>
      <dc:creator>aaronesteban1</dc:creator>
      <pubDate>Thu, 28 Nov 2019 16:23:55 +0000</pubDate>
      <link>https://dev.to/aaronesteban1/php-comment-system-with-replies-4d4c</link>
      <guid>https://dev.to/aaronesteban1/php-comment-system-with-replies-4d4c</guid>
      <description>&lt;p&gt;I have code that is able to capture the initial comment and the 1st level of replies, but it doesn’t seem to capture the reply to a reply. I know that it requires an indefinite code using some form of recursion, but not quite sure how to properly implement it. Here's the code I'm using:&lt;/p&gt;

&lt;p&gt;&amp;lt;?php&lt;br&gt;
$conn = new mysqli('localhost', 'root', 'Jordan123', 'commentsystem2');&lt;/p&gt;

&lt;p&gt;$sql1 = "SELECT * FROM comments WHERE r_to = 0";&lt;br&gt;
$result1 = $conn-&amp;gt;query($sql1);&lt;/p&gt;

&lt;p&gt;while($row1 = $result1-&amp;gt;fetch_assoc()) {&lt;br&gt;
       $c_id = $row1['id'];&lt;br&gt;
       $c_name = $row1['name'];&lt;br&gt;
       $c_comment = $row1['comment'];&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   echo '
   &amp;lt;div class="comments" style="position:relative; margin:auto; width:25%;"&amp;gt;
      &amp;lt;div&amp;gt;ID# '.$c_id.'&amp;lt;/div&amp;gt;
      &amp;lt;div style="font-weight:bold;"&amp;gt;'.$c_name.'&amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;'.$c_comment.'&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;
   &amp;lt;/div&amp;gt;
   ';

   $sql2 = "SELECT * FROM comments WHERE r_to = $c_id";
   $result2 = $conn-&amp;gt;query($sql2);

      while($row2 = $result2-&amp;gt;fetch_assoc()) {
          $r_id = $row2['id'];
          $r_name = $row2['name'];
          $r_comment = $row2['comment'];
          $r_to = $row2['r_to'];
          echo '
          &amp;lt;div class="comments" style="position:relative; margin:auto; width:25%; padding-left:80px;"&amp;gt;
             &amp;lt;div&amp;gt;ID# '.$r_id.'&amp;lt;/div&amp;gt;
             &amp;lt;div style="font-weight:bold;"&amp;gt;'.$r_name.' replied to '.$c_name.'&amp;lt;/div&amp;gt;
             &amp;lt;div&amp;gt;'.$r_comment.'&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;&amp;lt;/div&amp;gt;
          &amp;lt;/div&amp;gt;
          ';

      }//end of 1st while loop that captures comments.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;}//end of 1st while loop that captures comments.&lt;/p&gt;

&lt;p&gt;$conn-&amp;gt;close();&lt;br&gt;
?&amp;gt;&lt;/p&gt;

&lt;p&gt;Notice how some of the replies to replies that are in the table, are missing on output.&lt;/p&gt;

</description>
      <category>php</category>
      <category>comment</category>
      <category>system</category>
    </item>
  </channel>
</rss>
