I'm struggling to link 2 tables together so that I can fill out information for my PHP script
I have 2 tables feed
and u_feed
U_FEED
id | uid | fid
1 | 2 | 1
FEED
id | url | title | favicon
1 | http://example.com | domain | http://example.com/favicon.ico
The current user id (uid) will be 2
I have tried but to no luck
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
JOIN feed f ON u.fid = '2'
You're not specifying what column to join the two tables on, and it looks like you're using the wrong column to filter based on the User Id. Try something like this:
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
INNER JOIN feed f ON f.id = u.fid
WHERE u.uid = '2'
Try this one first join your tables then use WHERE
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
JOIN feed f ON u.fid = f.id
WHERE u.fid='2'
Or
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
JOIN feed f ON (u.fid = f.id AND u.fid='2' )// join tables with multiple conditions
Specify the JOIN condition correctly. There must a column in both tables that correspond to each other. In this case it seems to be u_feed.fid
and feed.id
.
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
JOIN feed f ON f.id = u.fid
WHERE u.uid = '2'
I think is a typo or confusion - you said
The current user id (uid) will be 2
but query by fid = 2.
SELECT u.uid, f.url, f.title, f.favicon
FROM u_feed u
JOIN feed f ON u.fid = f.id
WHERE u.uid = 2
Hope this helps