I can not bring all records from the table

1

Hello, I'm not able to show all the records in a DB table row, 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 site admin mode)

Hereismyselectinphpscript:

$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 result of the query (above): yes, it is only bringing one of the 5 related data. What can it be?

    
asked by anonymous 27.07.2015 / 15:16

1 answer

1

Dude, I believe the problem is just in join, since it does not return data if there is no match in the two tables, try using LEFT OUTER JOIN instead of INNER JOIN or LEFT JOIN only.

It would be something like:

$query_noticiasrelacionadas = "SELECT * "
                    . "FROM tbnoticiasrel AS nr "
                    . "LEFT OUTER JOIN tbnews AS n ON nr.id_noticia_relacionada = n.id "
                    . "WHERE nr.id_noticia = " . $_REQUEST[idNoticia];

Hope it helps

    
03.05.2016 / 02:03