There is a query to the database:

SELECT * FROM content INNER JOIN users ON (content.user_id = users.id) INNER JOIN categories ON (content.category_id = categories.id) 

After that, I get an array in PHP:

 for ($i = 0; $i < mysqli_num_rows($result); $i++) { $row[] = mysqli_fetch_assoc($result); } 

In the template using Smarty display entries:

 {foreach $row as $item} <h3><a href="content.php?id={$item.id}">{$item.title}</a></h3> <p class="date"><b>Дата добавления:</b> {$item.pubdate}</p> <p class="autor"><b>Опубликовано:</b> {$item.nickname}</p> <p class="category"><b>Теги:</b> {$item.category_name}</p> <div class="description">{$item.content}</div> <a href="content.php?id={$item.id}" class="btn btn-info">Подробнее...</a> {/foreach} 

The problem is that the element of the array {$item.id} is not chosen, i.e. the element corresponds to the category_id table in the category table, i.e. the last id value that I attach to the table using INNER JOIN .

How to write a query with JOIN ?

    2 answers 2

    Specify specific fields in the request, instead of * :

     SELECT content.id, <все остальные нужные поля через запятую с указанием таблиц> FROM content INNER JOIN users ON (content.user_id = users.id) INNER JOIN categories ON (content.category_id = categories.id) 

      ATP helped aliases to the plates so that there was not too much. The request turned out such

       SELECT c.id, c.title, c.content, c.pubdate, u.nickname AS user, cat.category_name AS tag FROM content AS c INNER JOIN users AS u ON c.user_id = u.id INNER JOIN categories AS cat ON c.category_id = cat.id