Create unique links for indvidual elements of a PHP generated table

Posted by typoknig on Stack Overflow See other posts from Stack Overflow or by typoknig
Published on 2010-06-17T05:26:02Z Indexed on 2010/06/17 5:33 UTC
Read the original article Hit count: 141

Filed under:
|
|
|

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:

        <table>

            <tr>

                <td id="content_heading" width="25px">ID</td>
                <td id="content_heading" width="150px">Last Name</td>
                <td id="content_heading" width="150px">First Name</td>
                <td id="content_heading" width="75px">SSN</td>

            </tr>

            <?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 < $num; $i++){

                    $row = mysql_fetch_array($result);

                    $class = (($i % 2) == 0) ? "table_odd_row" : "table_even_row";

                    echo "<tr class=".$class.">";

                        echo "<td>".$row[id]."</td>";
                        echo "<td>".$row[l_name]."</td>";
                        echo "<td>".$row[f_name]."</td>";
                        echo "<td>".$row[ssn]."</td>";

                    echo "</tr>";

                }

            ?>      

        </table>

© Stack Overflow or respective owner

Related posts about php

Related posts about JavaScript