Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. id | post | userId |
  2. ---------|---------------|----------|
  3. 1 | "hello" | 1 |
  4. 2 | "world" | 1 |
  5. 3 | "ouch" | 2 |
  6. 4 | "test" | 1 |
  7.  
  8. id | postId | fileName | time |
  9. ---------|---------------|----------|----------|
  10. 1 | 1 |"hey.jpg" | 0 |
  11. 2 | 1 |"test.png"| 53252354 |
  12. 3 | 2 |"asd.png" | 0 |
  13. 4 | 4 |"asd2.png"| 0 |
  14.  
  15. $qry = $db->prepare('SELECT post.id, post.post, post.userId, att.fileName, att.time
  16. FROM posts AS post LEFT JOIN attachments AS att ON att.postId = post.id');
  17. $qry->execute();
  18. $postsArray = $qry->fetchAll(PDO::FETCH_ASSOC);
  19.  
  20. [{'id': 1,
  21. 'post': 'hello',
  22. 'userId': 1,
  23. 'attachments': [{'fileName': 'hey.jpg', 'time:' 0}, ... ]
  24. }, ... ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement