Jump to content

Please Help! Database Query to join two tables


topcat1979

Recommended Posts

--------------------------------------------------------------------------------

Hi there,

I have a site I'm working on which is basically a shopping portal. Within this site I have an area where customers can view there previous purchases, and in this area they can view the product id, price they paid, sellers id, date, etc.

I have two tables, shop_users and shop_items. These two tables have some fields in common, one being the seller id, which is a number and is present in both tables under two different field titles; these are: shop_users = id and shop_items = ownerid. To cut along story short I wish to join these two fields, by comparing them in a query and output the result as the username of the seller from the shop_user table.

My current code looks a little like this:

$getseller="SELECT u.username FROM shop_users u, shop_items a WHERE a.ownerid=u.id";
$seller=mysql_query($getseller)

I think this is the best way of doing it but unfortunately I have had no luck in getting it to work.

If you could point out where I'm going wrong, I'd really appreciate it!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.