![]() |
Quick PHP + MySQL Query help!
I need a little help with a query. It's for a site that allows users to post up their original audio file (or "track"). Users can listen, vote, etc. The problem is in outputting the data from 2 tables in the DB.
Here's the deal: table1 - "tracks" table2 - "users" "tracks" and "users" have a common column "username". The query so far: $query = "SELECT id, name, username, title, hitCount, timestamp FROM tracks ORDER BY id DESC LIMIT $offset, $rowsPerPage"; The above outputs all the tracks that have been posted and pages it to 10 results per page. Everything is fine with that. What I need is a join that will allow me to output the users' profile image which is in table2 in a column called "thumb". Any help is greatly appreciated! I've fucked with this for days. Also I haven't been around much so I don't know if anyone still goes to Web Q&A so please forgive the posting in here. :winkwink: |
Code:
SELECT a.thumb as thumb,id,name,username,title,hitCount,timestamp FROM tracks,users as a WHERE username=a.username ORDER BY id DESC LIMIT $offset, $rowsPerPage; |
Quote:
table1 - tracks id name TYPE size path username * title hitCount timestamp table2 - users username * password userid userlevel timestamp website about hometown postal thumb Thanks for helping. :pimp |
whats the error message ?
|
Dude instead of selecting 90% of the fields, just do the whole thing for the sake of simplicity:
SELECT * FROM table WHERE username=... |
Quote:
From: $result = mysql_query($query) or die('Error, query failed'); PHP-CODER-FOR-HIRE: I've tried that but I've added them that way to help me understand what's going on. |
Quote:
I asked about the error message the query is producing not some random message you chose to display when it fails. |
Quote:
Column: 'username' in field list is ambiguous |
Code:
select a.thumb,b.* FROM users as a, tracks as b |
Quote:
|
just goto www.mysql.net . Have fun
|
All times are GMT -7. The time now is 11:39 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123