Search code examples
phpdatabaseportal

get related data from db via anchor tag


My code:

<?php
if (isset($_GET["q"]))
{
    $q= $_GET["q"];   # this is team name 

    $link=mysqli_connect("localhost","root","");
    mysqli_select_db($link,"onesports");
    $result=mysqli_query($link," select * from team where team_name='" .$q. " ' ");
    $result2=mysqli_query($link,"select  players.full_name, team.* from players,team where team.team_name='" .$q. " ' and players.team_name=team.team_name ");
    while($row = mysqli_fetch_array($result)) {
  ?>
    <table>
        <tr>        
        <td style="font-size: 30px; font-variant-caps:petite-caps;" > <?php echo $row['team_name'];  ?> </td>
        <td style="text-transform: capitalize; "> <?php  echo "(";    echo  $row['city'] ; echo ",";  echo $row['prov']; echo ")";  ?> </td>            
 </tr>
   <tr>
        <td style="text-transform: capitalize;">      
            <?php echo $row['captain']; echo "(c)";  ?>        
        </td>         
        <td style="text-transform: capitalize;"> <?php echo $row['coach'];  ?> </td>
   </tr>    

    </table>
   <hr>
       <?php
    }
    echo '<table cellpadding="0" cellspacing="0" class="db-table">';
    echo "<tr>";
    echo "<th>";
    echo "Players";
    echo "</th>";
    echo "</tr>";
    while($row = mysqli_fetch_array($result2)) {    
        echo "<tr>"; 
        echo "<td>";
        echo '<a href= " "  >' . $row['full_name'] . '</a>';
        echo "</td>";
        echo "</tr>";
    }
    echo "</table>";

The problem is that I'm getting full_name dynamically, every name has some details in db I want to get. When I click on full_name, I want it to give me all the related data from the DB. This is the part with the links:

echo '<table cellpadding="0" cellspacing="0" class="db-table">';
echo "<tr>";
echo "<th>";
echo "Players";
echo "</th>";
echo "</tr>";
while($row = mysqli_fetch_array($result2)) {    
    echo "<tr>"; 
    echo "<td>";
    echo '<a href= " "  >' . $row['full_name'] . '</a>';
    echo "</td>";
    echo "</tr>";
}
echo "</table>";

So kindly help me. Do you suggest that I use any other tag rather than an anchor tag, or you can tell me how to get data this way?


Solution

  • As I got the point, you need to retrieve the information by clicking the relevant link. You can use the following structure:

    echo '<a href="?FN='.$row["full_name"].'">'.$row["full_name"].'</a>';
    

    Then at your server-side code, get the data by using

    $_GET['FN']

    I hope this answer help you as well as.