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.

Post New Thread Reply

Register GFY Rules Calendar Mark Forums Read
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 01-25-2007, 10:11 AM   #1
dirtysouth
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
dirtysouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:20 AM   #2
darksoul
Confirmed User
 
darksoul's Avatar
 
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;
__________________
1337 5y54|)m1n: 157717888
BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
Cambooth
darksoul is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:28 AM   #3
dirtysouth
Confirmed User
 
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
Quote:
Originally Posted by darksoul View Post
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;
Query failed, BUT I think it's because I didn't give you enough info.

table1 - tracks

id
name
TYPE
size
path
username *
title
hitCount
timestamp

table2 - users

username *
password
userid
userlevel
email
timestamp
website
about
hometown
postal
thumb

Thanks for helping.
__________________
no sig
dirtysouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:34 AM   #4
darksoul
Confirmed User
 
darksoul's Avatar
 
Join Date: Apr 2002
Location: /root/
Posts: 4,997
whats the error message ?
__________________
1337 5y54|)m1n: 157717888
BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
Cambooth
darksoul is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:35 AM   #5
PHP-CODER-FOR-HIRE
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=...
__________________
PHP-CODER-FOR-HIRE is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:50 AM   #6
dirtysouth
Confirmed User
 
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
Quote:
Originally Posted by darksoul View Post
whats the error message ?
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
dirtysouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 10:55 AM   #7
darksoul
Confirmed User
 
darksoul's Avatar
 
Join Date: Apr 2002
Location: /root/
Posts: 4,997
Quote:
Originally Posted by dirtysouth View Post
Error, query failed

From:

$result = mysql_query($query) or die('Error, query failed');
I hope that is a joke.
I asked about the error message the query is producing not
some random message you chose to display when it fails.
__________________
1337 5y54|)m1n: 157717888
BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
Cambooth
darksoul is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 11:01 AM   #8
dirtysouth
Confirmed User
 
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
Quote:
Originally Posted by darksoul View Post
I hope that is a joke.
I asked about the error message the query is producing not
some random message you chose to display when it fails.
Sorry about that.

Column: 'username' in field list is ambiguous
__________________
no sig
dirtysouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 11:05 AM   #9
darksoul
Confirmed User
 
darksoul's Avatar
 
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;
__________________
1337 5y54|)m1n: 157717888
BM-2cUBw4B2fgiYAfjkE7JvWaJMiUXD96n9tN
Cambooth
darksoul is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 11:08 AM   #10
dirtysouth
Confirmed User
 
Join Date: Jul 2003
Location: Mobtown
Posts: 2,613
Quote:
Originally Posted by darksoul View Post
Code:
select a.thumb,b.* FROM users as a, tracks as b
WHERE a.username=b.username
ORDER BY id DESC LIMIT $offset, $rowsPerPage;
You da' man. Thanks, I appreciate that.
__________________
no sig
dirtysouth is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 01-25-2007, 11:50 AM   #11
grumpy
Too lazy to set a custom title
 
grumpy's Avatar
 
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
grumpy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks
Thread Tools



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.