Deniz
Deniz

Reputation: 107

Generate different link per id

first of all I know there are post like this one, but I cant seem them to work for my project.

Like the title says I want to create multiple pages with on php file.

  1. First off all I made the query that I needed for this:

    SELECT IFNULL(CONCAT(firstname, ' ', lastname), '') AS lastname FROM ps_employee WHERE firstname NOT IN ('Erik','Roy','Kevin','Nop','Raimond','external')
    

This part is easy works fine.

  1. And now I need my php file I called it staff.php with header and body.

I added this into staff.php:

     <?php 

$query = "SELECT IFNULL(CONCAT(firstname, ' ', lastname), '') AS lastname
          FROM expoled.ps_employee
          WHERE firstname NOT IN ('Erik','Roy','Kevin','Nop','Raimond','external');";

        $exec = mysqli_query($con,$query);
        while($row0 = mysqli_fetch_array($exec)){

echo '  <a href="/stats/=id1" class="list-group-item">'.$row0['lastname'].'</a>';

        }
        ?>

The result off this is like:

║  hans cover  ║
║  dake jhon   ║
║  rot gham    ║

But now when I click on them it redirects me to /stats/=id1 for all the employees I know that I do it wrong but this is for so far I can go.

I did search for $_GET['action'] ifelse but I messed it up.

I can add all the employees hardcoded but that's not what I want.

Upvotes: 0

Views: 65

Answers (2)

Kuldeep Singh
Kuldeep Singh

Reputation: 696

I assume 'id' is the userId in your ps_employee table

$query = "SELECT IFNULL(CONCAT(firstname, ' ', lastname), '') AS lastname, id as userId
              FROM expoled.ps_employee
              WHERE firstname NOT IN ('Erik','Roy','Kevin','Nop','Raimond','external');";

        $exec = mysqli_query($con,$query);

        while($row0 = mysqli_fetch_array($exec)){

echo '  <a href="/stats/'.$row0['userId'].'" class="list-group-item">'.$row0['lastname'].'</a>';

        }

Upvotes: 1

Lelio Faieta
Lelio Faieta

Reputation: 6689

Your query should be:

$query = "SELECT IFNULL(CONCAT(firstname, ' ', lastname), '') AS lastname, id
          FROM expoled.ps_employee
          WHERE firstname NOT IN ('Erik','Roy','Kevin','Nop','Raimond','external');";

Assuming that you have an id for each user and the field is named id.

Then when you build the links:

while($row0 = mysqli_fetch_array($exec)){
    echo '  <a href="/stats?=id'.$row0['id'].'" class="list-group-item">'.$row0['lastname'].'</a>';
}

I can help you with the first part of the link if you explain a bit better where do you expect the user to be redirected on click.

In my example anyway on the target page you will be able to do

$id = $_GET['id'];

and then you can use the user id on your logic.

Upvotes: 1

Related Questions