Reply
Joining tables help
Old 04-02-2007, 08:25 PM Joining tables help
Experienced Talker

Posts: 46
I'm having trouble with a query and hopefully someone can help me.

I have two tables in my database that I'm trying to join, so I can retrieve the art from the database but by what the user has stored.

art
artid thumbnail_url
1 images/pic.jpg
2 images/smile.jpg


users_art
userid artid
1 1
1 2

as you can tell, artid is the same and I'm trying to join them in my query. I came up with this:
PHP Code:
$query "SELECT art.thumbnail, users_art.userid FROM art, users_art WHERE art.artid = users_art.artid AND users_art.userid='$temp_id'"
$temp_id is the user's ID, so when they login it can pull the results by the user. I get no results, so I assume something is wrong.
bld44 is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 04-03-2007, 04:37 AM Re: Joining tables help
chrishirst's Avatar
Super Moderator

Posts: 16,467
Location: Blackpool. UK
you have the ID variable surrounded by quotes
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-03-2007, 05:11 PM Re: Joining tables help
Experienced Talker

Posts: 46
Right- but I think I did it without the whole AND.... and it still didn't work. Is that query correct for what I'm trying to do here?
bld44 is offline
Reply With Quote
View Public Profile
 
Old 04-03-2007, 07:15 PM Re: Joining tables help
chrishirst's Avatar
Super Moderator

Posts: 16,467
Location: Blackpool. UK
Or a join

Code:
SELECT art.thumbnail_url, users_art.userid FROM users_art INNER JOIN  art ON users_art.artid = art.artid WHERE users_art.userid = $temp_id;
Should work ok (Not tested BTW)
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Indifference will be the downfall of mankind, but who cares?
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-03-2007, 07:36 PM Re: Joining tables help
Experienced Talker

Posts: 46
Ok, that works! Thank you very much.
bld44 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Joining tables help
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.13193 seconds with 12 queries