title: How do I create links in the cells of a PHP generated table?
body: <p>I have a table generated from some PHP code that lists a SMALL amount of important information for employees.  I want to make it so each row, or at least one element in each row can be clicked on so the user will be redirected to ALL of the information (pulled from MySQL database) related to the employee who was clicked on.  I am not sure how would be the best way to go about this, but I am open to suggestions.  I would like to stick to PHP and/or JavaScript.  Below is the code for my table:</p>
  
  <pre><code>        &lt;table&gt;
  
              &lt;tr&gt;
  
                  &lt;td id="content_heading" width="25px"&gt;ID&lt;/td&gt;
                  &lt;td id="content_heading" width="150px"&gt;Last Name&lt;/td&gt;
                  &lt;td id="content_heading" width="150px"&gt;First Name&lt;/td&gt;
                  &lt;td id="content_heading" width="75px"&gt;SSN&lt;/td&gt;
  
              &lt;/tr&gt;
  
              &lt;?php
  
                  $user = 'user';
                  $pass = 'pass';
                  $server = 'localhost';
  
                  $link = mysql_connect($server, $user, $pass);
  
                  if (!$link){
                      die('Could not connect to database!' . mysql_error());
                  }
  
                  mysql_select_db('mydb', $link);
                  $query = "SELECT * FROM employees";
                  $result = mysql_query($query);
                  mysql_close($link);
  
                  $num = mysql_num_rows($result);                         
  
                  for ($i = 0; $i &lt; $num; $i++){
  
                      $row = mysql_fetch_array($result);
  
                      $class = (($i % 2) == 0) ? "table_odd_row" : "table_even_row";
  
                      echo "&lt;tr class=".$class."&gt;";
  
                          echo "&lt;td&gt;".$row[id]."&lt;/td&gt;";
                          echo "&lt;td&gt;".$row[l_name]."&lt;/td&gt;";
                          echo "&lt;td&gt;".$row[f_name]."&lt;/td&gt;";
                          echo "&lt;td&gt;".$row[ssn]."&lt;/td&gt;";
  
                      echo "&lt;/tr&gt;";
  
                  }
  
              ?&gt;      
  
          &lt;/table&gt;
  </code></pre>
  
  <p><strong>EDIT</strong></p>
  
  <p>Ok, after modifying what @DrColossos posted I have been able to get my links to work correctly, but now I'm having trouble with the uniqueness part.  Below is the code I am now using to create my table:</p>
  
  <pre><code>                        echo "&lt;td&gt;&lt;a href=Edit_Employee.php?".$row[id]."&gt;".$row[id]."&lt;/a&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;a href=Edit_Employee.php?".$row[id]."&gt;".$row[l_name]."&lt;/a&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;a href=Edit_Employee.php?".$row[id]."&gt;".$row[f_name]."&lt;/a&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;&lt;a href=Edit_Employee.php?".$row[id]."&gt;".$row[ssn]."&lt;/a&gt;&lt;/td&gt;";
  </code></pre>
  
  <p>This makes all of the elements of a row hyperlink to <code>Edit_Employee.php?**id**</code>.  For instance if the <code>id</code> was one the hyperlink would be <code>Edit_Employees.php?1</code>. <strong>Now what do I need to do in my <code>Edit_Employee.php</code> page to get or recognize the <code>id</code> in the link, because it is that <code>id</code> that is unique and that is what I need to base my MySQL search on.</strong></p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Figured it out.  This did the trick:</p>
  
  <p><code>$id = $_GET['id'];</code></p>
  
  <p>I found that creating my links as I did makes the <code>id</code> a global variable which PHP can pull from the hyperlink.  I used the code above in the page that the hyperlink points to and I was able to get what I wanted.  Not too hard, but frustrating if you don't know how it is done!</p>