title: Query the database in foreach results
body: <p>I'm trying to build a webpage with simple status posts. I've created foreach loop to query the database and load all the posts:</p>
  
  <pre><code> &lt;?php
   $user_id = Check::isLoggedIn();
   $dbstories = DB::query('SELECT * FROM stories WHERE user_id=:user_id ORDER BY story_time DESC', array(':user_id'=&gt;$user_id));
   $post_story = "";
   foreach($dbstories as $story) {
  
    ?&gt;
  
    &lt;div&gt;
      &lt;article&gt;
          &lt;div&gt;
            &lt;a href="profile.php"&gt;
              &lt;?php
                // to pull user first name
                $user_first = DB::query('SELECT user_first FROM users WHERE user_id=:user_id', array(':user_id'=&gt;$user_id))[0]['user_first'];
                echo $user_first;
               ?&gt;
            &lt;/a&gt;
            &lt;div&gt;
              &lt;time&gt;
                &lt;?php
                 // to pull post datetime
                 $post_time = $story['story_time'];
                 echo '&lt;time class="timeago" datetime="' . $post_time . '"&gt;&lt;/time&gt;';
                ?&gt;
              &lt;/time&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;?php
        // to pull post contents
        $post_story = $story['story_body'];
        if (strlen($post_story) &lt;= 25) {
          echo '&lt;h3&gt;' . $post_story . '&lt;/h3&gt;';
        } else {
          echo '&lt;p&gt;' . $post_story . '&lt;/p&gt;';
        }
        ?&gt;
        &lt;div&gt;
          &lt;div&gt;
            &lt;a href="#"&gt;
              &lt;svg class="thunder-icon"&gt;&lt;use xlink:href="icons/icons.svg#thunder-icon"&gt;&lt;/use&gt;&lt;/svg&gt;
              &lt;span&gt;
                &lt;?php
                 // to pull number of likes
                 $post_likes = $story['story_likes'];
                 echo $post_likes;
                ?&gt;
              &lt;/span&gt;
            &lt;/a&gt;
            &lt;!-- the same for comments and shares number goes here --&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div&gt;
  
          &lt;!-- This form over here should pull the story_id which is the post ID from the database like the other queries up there and post it next to the url then that will allow me to use it in isset($_GET['story_id']) and trigger a query to increment likes --&gt;
  
  
          &lt;form action="stories.php?post_id=&lt;?php $post_id = $story['story_id']; echo $post_id; ?&gt;" method="post" id="like_story"&gt;
            &lt;a href="#" class="btn btn-control" id="post_like"&gt;
            &lt;svg class="like-post-icon"&gt;&lt;use xlink:href="icons/icons.svg#thunder-icon"&gt;&lt;/use&gt;&lt;/svg&gt;
            &lt;/a&gt;
          &lt;/form&gt;
          &lt;!-- the same for comment and share goes here --&gt;
        &lt;/div&gt;
      &lt;/article&gt;
    &lt;/div&gt;
   &lt;?php 
    }
     ?&gt;
  </code></pre>
  
  <p>*Please read the comments within the code</p>
  
  <p>Everything works fine but, I still cant get each post's ID linked to the like button (like_story). It only access the most recent post's ID.</p>
  
  <p>Any workaround to reference the post ID (story_id)?</p>