Problems generating PHP page from dynamic menu link

1

I have a dynamic menu where it is generated from the tables in my database.

<?php
    $results = DB::query('select * from categoria');

    foreach ($results as $row) {
        echo '<a href="#" class="categoria">'.$row['Nome'].'</a>';
    }  
?>

I want to make a PHP code that generates a default page for each category, where all products in this category clicked on that page.

When I enter <a href="paginadeprocessamento.php" class="categoria"> I can not get the category that the user clicked on the menu.

I have tried to use name="" but I think it only works for form.

In short: I want to generate a page with all the products in the category where the user clicked on the dynamic menu, but I can not identify them later in the php he clicked on.

I gave a quick hand on htacess and I think it can help me, but I think I might have another solution for that.

    
asked by anonymous 02.04.2017 / 01:06

1 answer

1

To get some information via URL you have to go through a parameter.

 foreach ($results as $row) {    
 echo "<a href="paginadeprocessamento.php?categoria=".$row['Nome']." class="categoria">'.$row['Nome'].'</a>';

And in PHP you do $categoria = $_GET['categoria'];

select * from ???? where ???? = $categoria
  

The GET method is used when we want to pass a few / small information to perform a search or simply pass information to another page through the URL.

     

This method is very restricted in the size and quantity of information that is passed by the URL.

     

As you have already seen, the information you submit is visible to the visitor, so when you want to pass confidential parameters, such as passwords, you should not use this method. For this we have the POST.

    
02.04.2017 / 01:57