Is there any way to get a column value from $_GET without being passed in the URL?

Asked

Viewed 66 times

1

what I want to do and a system of related news, for now I have it

home php.

$noticias=$conn->prepare("SELECT * FROM `noticias` ORDER BY `id` DESC");

if(isset($nomeNoticia)||isset($slug)){

    $noticias->bindValue(":nomeNoticia",$nomeNoticia,PDO::PARAM_STR);
    $noticias->bindValue(":slug",$slug,PDO::PARAM_STR);

}

$noticias->execute();

$row=$noticias->fetchAll(PDO::FETCH_OBJ);

foreach($row as $listar){

    $nome=$listar->nomeNoticia;
    $slug=$listar->slug;

    echo '<a href="'.$urlBase.'/noticia/'.$slug.'">'.$nome.'</a>';

}

verNoticia.php

$verNoticia=$conn->prepare("SELECT * FROM `noticias` WHERE `slug` = '$post'");

if(isset($nomeNoticia)||isset($relacao)){

    $verNoticia->bindValue(":nomeNoticia",$nomeNoticia,PDO::PARAM_STR);
    $verNoticia->bindValue(":relacao",$relacao,PDO::PARAM_STR);

}

$infoEpisodio->execute();
$rowVNoticia=$verNoticia->fetchAll(PDO::FETCH_OBJ);

foreach($rowVNoticia as $listarNoticia){
    $nome=$listarNoticia->nomeNoticia;
    //unico jeito que pego a coluna relacao
    $relacao=$listarNoticia->relacao;

    echo '

         Nome: '.$nomeNoticia.'
         Categoria: '.$relacao.'

    ';

}

what I tried to

//pensei que o $_GET pegaria os valores da coluna relacao que eu imprimo acima
if(isset($relacao)){
   $relacao = $_GET['relacao'];
}
$relacionadas=$conn->prepare("SELECT COUNT(relacao) AS Relacao FROM `noticias` WHERE `relacao` LIKE '$relacao%'");

this gave indefinite variable in query Undefined variable: relacao

the purpose of this and only show the news that the column relacao be identical

example

Noticia 07 coluna relacao = aventura, esportes

Noticia 03 coluna relacao = aventura, esportes

Noticia 10 coluna relacao = aventura, esportes

Noticia 25 coluna relacao = aventura, esportes

  • What do you mean, go through the URL? get only picks up what’s in the URL, maybe it’s confusing it with the $_POST

  • @Marceloboni I need to recover the value of the relative column, without listing it and without going through the url, ie the code has to check which records have the same names in the field relationship, and bring only the same, understood ? to be clear, and a related system, example News 01 ->category sports, adventure, there brings the other news that the column relates to sports, adventures

  • Sorry, I can’t help you chat. I suggest [Dit] the question and try your as clear as possible about what you are trying to do (not about how you stifle which must be the solution!)

  • @bfavaretto what I want to do and very simple, I want to make a sisteminha of related news, example, I have News 01, this news 01 has the category of sport, adventure, then the guy clicks on it, opens it whole to read, then appears the other related news, example, News 05 has the category sport, adventure News 10 has the category sport, adventure, ie only shows those that are related, where the column relacao be identical to all, understood ?

  • 2

    I get it. So you already access your database and already receive the news data there, right? The title, the text, etc. The category does not come together? If it comes, that’s where you have to take it. Otherwise, you pull from the bank based on the code of the current news. I suggest, again, [Dit] the question trying to explain the problem in detail and where you are leaving from. Capable until along the way you can figure it out yourself.

  • Can you already show the news categories on the page? If so, you already have the value you need to use in your query!

  • @bfavaretto yes I show the value of categories, that I wanted to know, how to identify these values in my query

  • 2

    You need to show step by step on the question. for example... In my opinion... Like this: When the user clicks on the news the url looks like this: (url) and then I search the database like this:(search code) and then I have this... and then this... but I can’t do it...

  • You need to detail better

  • @Andreicoelho edited the question

  • 1

    You already have $relacao=$listarNoticia->relacao; in one of the archives. That’s not what you need?

  • @bfavaretto got it, in fact it was all right, what was not working out, was that when registering the category in the bank I removed all the accents, and in the listing I put the accents, then the query was not recognizing, what I did was leave one column with accents and another without accents, so it worked

Show 7 more comments
No answers

Browser other questions tagged

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