topcat1979 Posted November 13, 2006 Share Posted November 13, 2006 --------------------------------------------------------------------------------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! Quote Link to comment https://forums.phpfreaks.com/topic/27095-please-help-database-query-to-join-two-tables/ Share on other sites More sharing options...
stb74 Posted November 13, 2006 Share Posted November 13, 2006 topcatAre you getting an error message. Quote Link to comment https://forums.phpfreaks.com/topic/27095-please-help-database-query-to-join-two-tables/#findComment-124106 Share on other sites More sharing options...
stb74 Posted November 13, 2006 Share Posted November 13, 2006 try puting this on the endwhile ($row = mysql_fetch_array($seller)) { echo "$row[username]"; }See if you get any output Quote Link to comment https://forums.phpfreaks.com/topic/27095-please-help-database-query-to-join-two-tables/#findComment-124120 Share on other sites More sharing options...
fenway Posted November 15, 2006 Share Posted November 15, 2006 But "not working" do you mean an error, or no/unexpected output. Quote Link to comment https://forums.phpfreaks.com/topic/27095-please-help-database-query-to-join-two-tables/#findComment-125098 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.