Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to edit how you retrieve your comments using your function:</p> <pre><code>public function fetch_data($post_id){ global $pdo; $query = $pdo-&gt;prepare("SELECT * FROM comments WHERE post_id = ?"); $query-&gt;bindValue(1, $post_id); $query-&gt;execute(); return $query-&gt;fetch(); } </code></pre> <p>Should be something similar to:</p> <pre><code>public function fetch_data($post_id){ global $pdo; $query = $pdo-&gt;prepare("SELECT * FROM comments WHERE post_id = ?"); $query-&gt;bindValue(1, $post_id); $query-&gt;execute(); $results = array(); while($row = $query-&gt;fetch()){ $results[] = $row; } return $query-&gt;fetch(); } </code></pre> <p>Then it should work right as you think it should</p> <p>Your array previously was:</p> <pre><code>$comments = array( 'comment_id' =&gt; '1', 0 =&gt; '1', 'poster_name' =&gt; 'Mackan90096', 1 =&gt; 'Mackan90096', 'comment_content' =&gt; 'Hi! This is a test comment!', 2 =&gt; 'Hi! This is a test comment!', 'comment_timestamp' =&gt; '1385144211', 3 =&gt; '1385144211', 'post_id' =&gt; '4', 4 =&gt; '4' ); </code></pre> <p>And now it will be:</p> <pre><code>$comments = array( 0 =&gt; array( 'comment_id' =&gt; '1', 0 =&gt; '1', 'poster_name' =&gt; 'Mackan90096', 1 =&gt; 'Mackan90096', 'comment_content' =&gt; 'Hi! This is a test comment!', 2 =&gt; 'Hi! This is a test comment!', 'comment_timestamp' =&gt; '1385144211', 3 =&gt; '1385144211', 'post_id' =&gt; '4', 4 =&gt; '4' ) ); </code></pre> <p><strong>Note:</strong> using <code>$comments as $comment</code> as your foreach parameter is not good because $comment then overwrites your <code>Comment</code> class variable for later use.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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