title: Comparing products using PHP keeping the product on page as cookie
body: <p>I am trying to make a simple product compare system so far what i have made is that i am able to make it like when i click add to compare button i send jquery ajax request and get a call back response , of that product but i don't know how do it keep the product on page or display the items on compare-container as cookies so when users refresh the product is still there on place my code is like ,</p>
  
  <p>COMPARE.PHP</p>
  
  <pre><code>    &lt;html&gt;
      &lt;head&gt;
      &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"&gt;&lt;/script&gt;
  
      &lt;script&gt;
      $(document).ready(function(){
      $('.compare').click(function(){
      a = this.parentNode.getAttribute('data-compare-id');
         $.get('post.php?id='+a,status,foo);  
      });
  
      });             
           function foo(data){                  
           console.log();             
           }             
      &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
           &lt;?php         
      mysql_connect("localhost",'root','GoogleFacebook') or die(mysql_error());
      mysql_select_db('phones') or die(mysql_error());
      $query = mysql_query("SELECT * FROM mobiles");
      while($row = mysql_fetch_array($query)){
  
           echo "&lt;div class='phone' data-compare-id='".$row['id']."' style='display:inline-block;margin:10px;border:1px solid #ddd;padding:10px;' &gt;";
           echo "&lt;a href='".$row['phone_a']."' &gt;";
           echo $row['phone_name']."&lt;/br&gt;";
           echo "&lt;img src='".$row['phone_img']."' /&gt;";
           echo "&lt;/br&gt;";
           echo "&lt;/a&gt;";
           echo "&lt;button class='compare'&gt;Compare&lt;/button&gt;";
           echo "&lt;/div&gt;";        
      }
      ?&gt;
  
           &lt;div class='compare_container'&gt; 
           &lt;/div&gt;
      &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong><em>post.php</em></strong></p>
  
  <pre><code>&lt;?php
  if($_SERVER['REQUEST_METHOD'] == 'GET'){
  $id = $_GET['id'];
  mysql_connect("localhost",'root','GoogleFacebook') or die(mysql_error());
  mysql_select_db('phones') or die(mysql_error());
  $query = mysql_query("SELECT * FROM mobiles WHERE id='$id'");
  $row = mysql_fetch_array($query);
  echo "&lt;img src='".$row['phone_img']."' /&gt;";
  echo "&lt;span&gt;".$row['phone_name']."&lt;/span&gt;";}
  ?&gt;
  </code></pre>
  
  <p>I got confused how do i keep the contents on the page </p>