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! ???
Sorry away from my machine at the moment, but the basic outline:

[b]shop_users[/b]

id - number
username - char
name - char
surname - char
address - char
etc

[b]shop_items[/b]

id - number
title - char
description - char
ownerid - number
price - number
etc

shop_items['ownerid'] links in with shop_user['id']

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.