title: Passing values with $_SESSION
body: <p>I have a problem while passing a value of an element via <code>$_SESSION</code></p>
  
  <pre><code>&lt;?php
    session_start();
  ?&gt;
  &lt;?php
    echo "&lt;table&gt;";
    $con = mysql_connect("localhost","root","") or die ("problem");
    mysql_query("SET NAMES 'utf8'", $con);
    mysql_select_db("dedomena");
    $query = mysql_query("SELECT * FROM posts");
  
    $i = 1;
  
    while($query_row = mysql_fetch_assoc($query)) {
  
      echo  "&lt;tr&gt;&lt;td onclick='myFunction($i)'&gt;&lt;a
             href='page.php'&gt;".$query_row['title']."&lt;/a&gt;&lt;/td&gt;&lt;td&gt;$i&lt;/td&gt;";
      $i = $i + 1;    
    };
  
    echo "&lt;/table&gt;";
  ?&gt;
  &lt;script&gt;
    function myFunction($i) {
      alert(x);
      &lt;?php
        $_SESSION["id"] = $i;
      ?&gt;
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>The code on <em>page2.php</em> is</p>
  
  <pre><code>&lt;?php
    session_start();
  ?&gt;
  &lt;?php
    echo $_SESSION["id"];
  ?&gt;
  </code></pre>
  
  <p>When I click on an element on the first page I get the right id
  But when I try to pass the values to the second page it only shows me the number 10! 
  Note: the number 10 is obviously because of the <code>$i + 1</code> loop
  but how do I fix that?</p>