title: PHP Session only saves last item
body: <p>In follow up on this question: <a href="https://stackoverflow.com/questions/41634434/save-database-row-id-in-session-for-use-later">Save database row id in session for use later</a></p>
  
  <p>I'm now running into the following problem. The session is now (thankfully) stored. And the next page's content is filled dynamically. But ALL pages have the same <code>database id</code> and not the id that is specific for that link/item.</p>
  
  <p>I read something about the fact that I'm over writing the session ID's again and again. And I need to store the session in an Array.</p>
  
  <p>So what I did was the following, I changed this:</p>
  
  <pre><code>$identi = $row['Id'];
  $_SESSION["product_id"] = $identi;
  </code></pre>
  
  <p>Into this:</p>
  
  <pre><code>$identi = $row['Id'];
  if(!is_array($_SESSION['product_id'])) {
          $_SESSION['product_id']=array();
      }
          $_SESSION['product_id']=$row['Id'];;
  </code></pre>
  
  <p>But this still only stores the ID of the last item in the session an not the individual items. So I can have each item link with a specific ID.</p>
  
  <p>For good measure my SQL Query:</p>
  
  <pre><code>&lt;?php $sql = "SELECT * FROM assortiment WHERE Categorie = '$productid' ORDER BY Id DESC ";
  $result = $conn-&gt;query($sql);
  
  if ($result-&gt;num_rows &gt; 0) {
      // output data of each row
      while($row = $result-&gt;fetch_assoc()) {
  
          echo "&lt;a href='/dbtest/dinner/amsterdam/".$row["Slug"]. "/" . $row["Id"] . "'&gt;&lt;div class='products'&gt;&lt;div class='col-sm-3'&gt;&lt;div class='product-img'&gt;";
          $identi = $row['Id'];
          if(!is_array($_SESSION['product_id'])) {
              $_SESSION['product_id'] = array();
              }
              $_SESSION['product_id'] = $row['Id'];;
  
          echo "&lt;img src='http://www.example.nl/Uploaded_files/Thumbs/" .$row['Fotomateriaal']. ".jpg'&gt;";
          echo "&lt;/div&gt;&lt;/div&gt;&lt;div class='col-sm-6'&gt;";
          echo "&lt;div class='h2-container'&gt;&lt;h2&gt;" . $row["Product"]. "&lt;/h2&gt;&lt;/div&gt;" .  $row["Samenvatting"]. "";
          echo "&lt;/div&gt;&lt;div class='col-sm-3'&gt;&lt;div class='col-sm-12 text-right'&gt;
                      &lt;div class='border'&gt;
                          &lt;p style='margin-bottom:20px;width:30px;'&gt;&lt;i class='fa fa-heart' aria-hidden='true'&gt;&lt;/i&gt;&lt;/p&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;";
          echo "&lt;table&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;i class='fa fa-users' aria-hidden='true'&gt;&lt;/i&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;p&gt;vanaf 10 personen&lt;/p&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;i class='fa fa-clock-o' aria-hidden='true'&gt;&lt;/i&gt;&lt;/td&gt;
                      &lt;td&gt;" . $row["Tijdsduur"] .  " uur&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;
                      &lt;td&gt;&lt;i class='fa fa-euro' aria-hidden='true'&gt;&lt;/i&gt;&lt;/td&gt;
                      &lt;td&gt;vanaf " . $row["VerkoopPP40"] ." p.p. &lt;small&gt;excl btw&lt;/small&gt;&lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/a&gt;";
  
      if(isset($_SESSION['product_id'])){
      echo $_SESSION['product_id'];
      };
  
      }
  } else {
      echo "0 results";
  }?&gt;
  </code></pre>
  
  <p>Can anybody help me out with this one? As always thanks for the help in advance.</p>