1
Hello, I’m not able to show all the records of a row of the BD table, I can only bring the first record.
Here is my table:
CREATE TABLE IF NOT EXISTS `tbnoticiasrel` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`id_noticia` bigint(20) NOT NULL,
`id_noticia_relacionada` int(20),
`id_noticia_relacionada1` int(20),
`id_noticia_relacionada2` int(20),
`id_noticia_relacionada3` int(20),
`id_noticia_relacionada4` int(20),
PRIMARY KEY (`id`)
)
Here are my records in the table ( in admin mode of the website )
Here is my select in php script:
$query_noticiasrelacionadas = "SELECT * "
. "FROM tbnoticiasrel AS nr "
. "INNER JOIN tbnews AS n ON nr.id_noticia_relacionada = n.id "
. "WHERE nr.id_noticia = " . $_REQUEST[idNoticia];
here is the query result (above): Yes, it’s only bringing one of the five related data. what can be?
already tested LEFT JOIN?
– Ivan Ferrer
Yes, I have tested and the result is the same as for RIGHT JOIN
– Estácio Di Fabio
That one
WHERE nr.id_noticia = " . $_REQUEST[idNoticia]
shouldn’t beWHERE n.id_noticia = " . $_REQUEST[idNoticia]
?– Dener
So let me ask you something. Is this field nr.id_noticia common between the two tables? Because in ON you are calling a different relation. And in case if nr.id_noticia does not have in the two tables, the others will be ignored.
– Ivan Ferrer
No, Where is asking that When the id_noticia (from the main news being related) is equal to the news that is in the request. yes, the id_noticia of table nr is equal to the id field of table n.
– Estácio Di Fabio
From what I understand, you want to call the content by another id, but that relate by other values, the problem of this will be in Union, the "Where" will only bring content that has nr.id_noticia = value_searched, he will not bring news that were related by another condition unless both have the same related value... I understand?
– Ivan Ferrer
To Test, take the WHERE condition and run your query in phpmyadmin or Workbench, see if it is bringing all the news with nr.id_noticia that you want to bring in the listing. You have to double or more in nr.id_noticia
– Ivan Ferrer