With the MySQL database using php, there are articles on the site, links of this type are index.php?id=1 , that is, it shows the first entry in the table, where id=1 . The output of the article is approximately the code

 <?=stripslashes($row6['bodytext']);?> 

But now there is such a problem - there is a second table in which there are also articles, in the second table there are 3-4 articles that are in addition to the article from the first table. For example, in the first table there is an article with id=45 , in the second table there are articles id=1 , id=2 .

How to make it so that when a person views an article from the first table id=45 , on the page on the side, below or else where there were links to articles from the second table id=1 and id=2 .

  • There should be a connection between the tables, and the selection should be done JOIN-ohm ... - Yoharny Babai

2 answers 2

can not join

 SELECT t1.*, t2.* FROM table1 t1,table2 t2 WHERE t1.id=t2.id 

t2.id it should be the article id from the table1 table - articles from different tables will be linked with it.

    if correctly understood:
    Table 1:
    id | name | text
    table 2:
    id | name | text | ownerID

    if something like this, then

     select table1.name as name // Имя стати table1.text as text // Текст статьи table2.name as owner // Имя сопутствующей статьи table2.ownerID // Ид сопутствующей статьи from table1 left join table2 // присоиденяете Вторую таблицу с дочерними on table1.id = table2.ownerID // Задаете соответсвие по Ид заглавной статьи where table1.id = id // где id - Ид вашей статьи 
    • and how to paint it in php code ready? just not very strong in codes. just add <? ?> and all? - meravaz
    • @meravaz no, <? ?> not enough. Connection to the database, query to the database, processing the result. - Oleg