title: How to get the ID when selected the particular item?
body: <p>I have a page that display products and I would like to get the product ID when I click on the particular item and pass it to another page. </p>
  
  <p>May I know how can I achieve this? </p>
  
  <p>I always get the last PID, my code:</p>
  
  <pre><code>&lt;head&gt;
      &lt;title&gt;Toy-All&lt;/title&gt;
  
      &lt;!--Wilmos: Using external CSS File to format the page style and fonts.--&gt;
      &lt;link href="StyleSheet2.css"  rel="Stylesheet"  type="text/css"   /&gt;
  &lt;/head&gt;
  
  
  &lt;body&gt;
  
     &lt;form method = "post" action "getpid.php"&gt; 
  
  
      &lt;div class="stylediv2-Middle-Toy-all"&gt; 
  
          &lt;div class="transbox-Toy-all"&gt;
  
          &lt;?php
  
          //open connection to MySQL Server
          $connection = mysql_connect('localhost','root', '')
              or die ('Unable to connect to !');
  
          // select database for use
          mysql_select_db('we-toys') or die ('Unable to select database!');
  
  
          $query = 'SELECT p.*, price.priceN FROM product p, pricing price WHERE  p.pid = price.pid and p.PGroup = 1 and p.PType = 1';
          $result = mysql_query($query)
              or die ('Error in query: $query. ' . mysql_error());
  
          if (mysql_num_rows($result) &gt; 0)
          {   
              while ($row = mysql_fetch_array($result)) 
              {
  
              echo '&lt;div style="float:left;margin-right: 10px; margin-left: 10px;"&gt;&lt;img src="'.$row[5].'"  width=200px height=200px; ?&gt; &lt;/div&gt;
  
                    &lt;h3&gt;'.$row[1].'&lt;/h3&gt;
  
                                &lt;h1&gt;&lt;span style="color:red"&gt; $ '.$row[7].' &lt;/span&gt;
  
  
                                &lt;input type="hidden" name="pid" value= '.$row[0].' &gt;
                                &lt;input id="AddtoCart-Btn" type="Submit" value= "Add to Cart" &gt;
  
  
  
  
  
                                &lt;/h1&gt; 
  
                    ';
  
  
                  }
          }
              else
              {
                  echo "No rows found!";
              }
              mysql_free_result($result);
              mysql_close($connection);
  
              ?&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
     &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>