![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
|
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. ![]()
__________________
no sig |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Apr 2002
Location: /root/
Posts: 4,997
|
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; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 | |
Confirmed User
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
|
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. ![]()
__________________
no sig |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: Nov 2006
Posts: 1,090
|
Dude instead of selecting 90% of the fields, just do the whole thing for the sake of simplicity:
SELECT * FROM table WHERE username=...
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
|
Error, query failed
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.
__________________
no sig |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Join Date: Apr 2002
Location: /root/
Posts: 4,997
|
Quote:
I asked about the error message the query is producing not some random message you chose to display when it fails. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
|
Quote:
![]() Column: 'username' in field list is ambiguous
__________________
no sig |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: Apr 2002
Location: /root/
Posts: 4,997
|
Code:
select a.thumb,b.* FROM users as a, tracks as b WHERE a.username=b.username ORDER BY id DESC LIMIT $offset, $rowsPerPage; |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
|
Quote:
![]()
__________________
no sig |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Too lazy to set a custom title
Join Date: Jan 2002
Location: Holland
Posts: 9,870
|
just goto www.mysql.net . Have fun
__________________
Don't let greediness blur your vision | You gotta let some shit slide icq - 441-456-888 |
![]() |
![]() ![]() ![]() ![]() ![]() |