How do I use table attributes as variables?


I have this code:


$sql="select distinct * from dir, training_list_of_dir, trainings_of_dir
      where dir.personal_id=trainings_of_dir.personal_id and trainings_of_dir.training_tag=training_list_of_dir.training_tag
      and trainings_of_dir.Personal_ID='$emp_id'";

if (!mysqli_query($con,$sql))
    die('Error: ' . mysqli_error($con));

$result= mysqli_query($con,$sql);
echo"<table border='1'>
        <th>second name</th>
        <th>First name</th>
        <th>Training tag</th>
        <th>Date of last training</th>
        <th>Date of next training</th>
while ($row = mysqli_fetch_array($result))
    echo "<tr>";
    echo "<td>","<a href='some.php'>". $row['Second_name']."</a>", "</td>";
    echo "<td>","<a href='some.php'>".$row['First_name']."</a>" ,"</td>";
    echo "<td>","<a href='some.php'>". $row['Training_tag']. "</a>" ,"</td>";
    echo "<td>","<a href='some.php'>".$row['Training_name']. "</a>" ,"</td>";
    echo "<td>","<a href='some.php'>".$row['Date_of_last_training']. "</a>" ,"</td>";
    echo "<td>","<a href='some.php'>". $row['Date_of_next_training']. "</a>" ,"</td>";
    echo "</tr>";

echo "</table>";

I would like to use each link in table for something else. For example if I click on training tag it will show me the row in table with the training tag. Or if I click on Date_of_last_training it will show me all the people who was on training in this date.

So the problem is, when it shows me table with rows, how can I use name of attribute in the where clause? For example with the "date of last training", how can I get this date in where date_of_last_training = $date_of_last_training (from the table on clicked attribute)?

Change your while loop with this code. And in some.php page code your logic based on the type

 while ($row = mysqli_fetch_array($result))
        echo "<tr>";
        echo "<td><a href='some.php'>". $row['Second_name']."</a></td>";
        echo "<td><a href='some.php'>".$row['First_name']."</a></td>";
        echo "<td><a href='some.php?type=traintag&tag=".$row['Training_tag']."'>". $row['Training_tag']. "</a></td>";
        echo "<td><a href='some.php?type=trainname&tname=".$row['Training_name']."'>".$row['Training_name']. "</a></td>";
        echo "<td><a href='some.php?type=lasttrain&date=".$row['Date_of_last_training'].">".$row['Date_of_last_training']. "</a></td>";
        echo "<td><a href='some.php?type=nexttrain&date=".$row['Date_of_next_training']."'>". $row['Date_of_next_training']. "</a></td>";
        echo "</tr>";