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
@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
– goio
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
@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 ?– goio
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.
– bfavaretto
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
@bfavaretto yes I show the value of categories, that I wanted to know, how to identify these values in my query
– goio
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...
– Andrei Coelho
You need to detail better
– Andrei Coelho
@Andreicoelho edited the question
– goio
You already have
$relacao=$listarNoticia->relacao;
in one of the archives. That’s not what you need?– bfavaretto
@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
– goio