How to know which link class to select with php

Asked

Viewed 32 times

0

I’m creating a website that has information from multiple vendors accessed by an administrator. To display vendor data, I have their names in a table by selecting them from a Mysql database.

Taking the data:

$db = mysqli_connect($servername, $user_db, $pass_db, $nome_db) or die(mysqli_error());
    mysqli_select_db($db, $nome_db);
    $query_vendor = "SELECT * FROM users WHERE ID != 4";//id temporária do admin
    $result = mysqli_query($db, $query_vendor);
    $vendorData = mysqli_fetch_array($result);

Arrangement of sellers' names:

<?php
      do{
           echo "<tr><td><a href='vendorData.php' target='_blank' class='$vendorData[ID]'>$vendorData[USERNAME]</a></td></tr>";
          }while($vendorData = mysqli_fetch_array($result));
 ?>

On the page that I send all sellers, the vendorData.php, I need to show the name of the seller whose link was clicked. My question is: how do I know which link was clicked? I know I can catch the link class with the DOM Document (following this reply), but I don’t know how to define the variable value $classname to catch the right class.

1 answer

0


You will pass the parameter to the other page, through the protocol http GET, insert into the hrefthe following adjustment to pass as parameter:

<?php
      do{
           echo "<tr><td><a href='vendorData.php?id=".$vendorData[ID]."' target='_blank' class='$vendorData[ID]'>$vendorData[USERNAME]</a></td></tr>";
          }while($vendorData = mysqli_fetch_array($result));
 ?>

On the page vendorData.php capture id as follows:

$id = $_GET['id'];

This array will bring all parameters passed through the protocol http get.

  • Thanks, it worked out!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.