title: how to display data on button click in a loop using php
body: <p>I have a project in which I am displaying a button tag in a while loop.  On every button click I want to display an alert box with the respective UserId.  Here is my code:</p>
  
  <pre><code>    &lt;?php 
   $data = mysql_query("Select RegisterId,FName,Image1  from Information where RegisterID='$profileMonth1'") or die(mysql_error());
   while ($dis1 = mysql_fetch_array($data)) {
  ?&gt;    
  &lt;div id="demo1" value="&lt;?php echo "$RegisterId" ?&gt;"&gt;
  &lt;button onClick="validate()"&gt;Show Interest&lt;/button&gt;
  &lt;/div&gt; 
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>Here is my validate function:</p>
  
  <pre><code>   function validate1(id2)
                  {
     // var id2;
  
      id2 = document.getElementById('demo2').getAttribute('value');
                  alert(id2);
  }
  </code></pre>
  
  <p>But it is always showing me last user id .. whereas i want to display userid for every user on everyclick.</p>
  
  <p>Can someone help?</p>