How to pass data via get?

1

I have a problem. I need to create a page that lists all the records with the selected category.

  

Code where the person selects the category and when clicking, sends to the   page. (This code is working fine, just put it for better understanding.)

<h2 class="titulos">Categorias</h2>
   <div class="cat-lista list-group">
      <?php  
         $contador = mysql_query("SELECT DISTINCT categoria, count(id) as catqtde FROM postagens group by categoria");

         while($prod = mysql_fetch_array($contador)) { 

      ?>

     <a href="categoria.php" name="categoria">
        <?php echo $prod['categoria']; ?>
           <span class="badge bt-span badge-pill"><?php echo $prod['catqtde']; ?></span>
     </a>
        <?php } ?>
</div>
  

Code of the page that should list data with that category.

<?php 
    $ident = $_GET['categoria'];

$sqlstring = "SELECT * from postagens where categoria = $ident order by id DESC ";
  $query = @mysqli_query($mysql->con, $sqlstring);



  while ($dados = @mysqli_fetch_array($query)){
      setlocale(LC_TIME,'pt_BR','pt_BR.utf-8','portuguese');
      date_default_timezone_set('America/Sao_Paulo');
      $datinha = date('d/m/Y', strtotime($dados['agendado']));
?>


        <div class="col-lg-3 col-md-6 col-sm-12 col-all-post" > 
            <div class="card post-item shadow">
                <a href="postagem.php?id=<?php echo $dados['id'] ?>&<?php echo slug($dados['titulo'])  ?>"><img class="card-img-top post-item-img" src="<?="admin/img/".$dados['foto']?>"></a>
                <div class="card-body">
                <div class="d-flex justify-content-between">
                    <div class="categoria-span cat-span-post">    
                        <a href="#"><span><?=$dados['categoria']?></span></a>
                    </div><!--categoria-span-->
                    <div class="info-span-blog">
                        <span><img src="assets/img/icon-cal.png"><?= $datinha ?>  </span>
                    </div><!--info-span-->
                </div>
                    <a href="postagem/<?php echo $dados['id'] ?>/<?php echo slug($dados['titulo'])  ?>"><h4 class="card-title d-flex align-items-end"><?=$dados['titulo'];?></h4></a>
                        <a href="postagem/<?php echo $dados['id'] ?>/<?php echo slug($dados['titulo'])  ?>"><h5 class="card-title"><?=$dados['subtitulo']?></h5></a>
                </div><!--card-body-->
            </div><!--card-->
        </div><!--col-lg-->



 <?php   

}
$mysql->fechar();

?>

    </div>

The error that appears to me is this:

  

Notice: Undefined index: category in D: \ Files \ USBWebserver   2 \ root \ site \ category.php on line 10

    
asked by anonymous 09.11.2018 / 13:36

2 answers

0

To get the data sent by GET you need to put the parameters in your href. See:

<a href="categoria.php?categoria=valorDoParametro" name="categoria">
    <?php echo $prod['categoria']; ?>
       <span class="badge bt-span badge-pill"><?php echo $prod['catqtde']; ?></span>
 </a>

So on the other page you get this value the way you did it.

$ident = $_GET['categoria'];

What you're missing is when you declare the parameter via link, it does not work if you just put a "name" in your href.

    
09.11.2018 / 13:52
0

In this section here:

<a href="categoria.php" name="categoria">

do so:

<a href="categoria.php?categoria=<?php $prod['categoria']; ?> " name="categoria">

Let's say you have a category called Test, the url looks like this:

categoria.php?categoria=teste , so this $ident = $_GET['categoria']; will recognize the variable GET.

Explanation

When you want to spend something for GET, always put in the URL like this:

url.php?nomedoparamento=valor

If you want more than one parameter, you can do so using & amp ;:

url.php?parametro1=teste&parametro2=teste2

    
09.11.2018 / 13:52