Problems generating PHP page from dynamic menu link

Asked

Viewed 46 times

1

I have a dynamic menu in which it is generated from the tables of 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 code in PHP that generates a default page for each category, where this page appears all products of this category clicked.

When I put <a href="paginadeprocessamento.php" class="categoria"> i can’t get the category the user clicked on the menu.

I’ve tried using the 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’t identify later in the php in which he clicked.

I gave a quick read on htacess and I think he can help me, but I think there might be another solution to this.

  • how is this menu? links menu? <a href="#" class="category">'. $Row['Name']. </a>

1 answer

1


To get some information via URL you have to pass 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 little/little information to perform a search or simply pass information to another page through the URL.

This method is very restricted as to the size and amount of information that is passed through the URL.

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

  • I had found another method but yours was better. Thank you very much.

Browser other questions tagged

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