The situation is the following -

There are two tables in the database, one with articles - posts , the second with user data - users .

For the page of all articles, the query in the database works correctly, displays data from two tables.

 SELECT posts.*, users.name, users.city FROM posts LEFT JOIN users ON posts.user_id=users.id WHERE posts.type='post' ORDER BY id DESC 

A separate article opens through $_GET (post.php?id=<?php echo $art['id']; ?>) And the query on the page of the separate article is now this -

 "SELECT * FROM `posts` WHERE `id` = " . (int) $_GET['id'] 

Only data from the posts table is pulled here.

The question is how to make a query to the database on the output page of a separate article in order to pull data from the users and posts tables for example users.name ?

/ - / - / - / - ///

Thank you, it works. There was another question. In the users table there is a column stream_profile containing extended user profile data in this format

a: 10: {s: 5: "photo"; s: 14: "123456789.png"; s: 5: "cover"; s: 14: "987654321.jpg"; s: 4: "city"; s : 38: "ADDRESS"; s: 4: "site"; s: 21: "site.ua"; s: 2: "vk"; s: 0: ""; s: 7: "twitter"; s: 29: "twitter.com /"; s: 2: "fb"; s: 35: "facebook.com"; s: 6: "google"; s: 49: "plus.google.com"; s: 9 : "instagram"; s: 37: "instagram.com"; s: 7: "youtube"; s: 0: "";}

Screen data in the column -> https://api.monosnap.com/rpc/file/download?id=HwOqDVzIOyrJF6yELYb8znc2dU54CS

Query to DB on output page -

$ articles = mysqli_query ($ connection, "SELECT posts. *, users.name, users.phone, users.stream_profile, users.city FROM posts LEFT JOIN users ON posts.user_id = users.id WHERE posts.id =". (( int) $ _GET ['id']. "");

works correctly, but the output of the picture from users.stream_profile does not work -

img src = "/ uploads / <? php echo $ art ['stream_profile'] ['cover'];?>" alt = "" Nothing is output

Question - How to correctly write output from stream_profile photo or cover data

Thanks in advance for your reply.

  • Just in the WHERE your first request, add AND posts.id= ".(int) $_GET['id']." - Peresada
  • Thanks, it worked! If it is not difficult, look at the addition to the question. There is another nuance. Thank you in advance. - vlsp

0