Old 02-11-2008   #1 (permalink)
Registered User
 
Join Date: Feb 2008
Posts: 2

New to PHP, confused with LEFT JOIN

Hi all. I really love your site...and have learned a good bit from tutorials provided!

I am trying to write a program addition to an application we currently are using. What it needs to do is this in each row:

Display all users name
Show all users total points per category
Show all their total overall points



MySQL info:


The "points" table has a column (points) which is where each entry of points is stored..nothing major there. It also has a column (user_id) which corresponds with the "user" table to get the users (char_name). The "points" table also has and a (custom_event_id) which matches the (point_cat_description_id) of the "point_cat_description" table to get the (name).


I am having headaches over this because I know my answer is simple...I just can't get it right. The SQL query that I have is:

Quote:
SELECT points, user_id, custom_event_id FROM points
LEFT JOIN user ON points.used_id=user.user_id
LEFT JOIN point_cat_description ON points.custom_event_id=point_cat_description.point _cat_description_id
I think the query is right...or close...I just don't know how to get the values that I need from joining the tables...

Another small problem I am having is deciding if I am going to use a for or do...while loop to display the data (leaning towards a for).

I REALLY appreciate ANY and ALL help, and thank you for helping in advance !
jayemsee283 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-11-2008   #2 (permalink)
Registered User
 
Join Date: Feb 2008
Posts: 2

Sorry to bump, but this is driving me a little crazy lol..
jayemsee283 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-14-2008   #3 (permalink)
Eternal Being
 
Join Date: Feb 2006
Location: Finland
Posts: 239

You get the values just like you have used the values in join, by prefixing them with the correct table name. You can also use shorter names which makes it a bit clearer like
Code:
select u.user_id from users u
(not sure if that's the format for mysql)

For looping through the resultset I would use while but I guess something else works just fine too.
__________________
Telos is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-14-2008   #4 (permalink)
Registered User
 
Tablet205's Avatar
 
Join Date: Feb 2008
Posts: 5

This might help

SQL

Join to see stuff on php.
Tablet205 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-14-2008   #5 (permalink)
Janitor of Lunacy
 
tamlin's Avatar
 
Join Date: May 2006
Location: Sitting in the Wishing Chair
Posts: 4,829

Quote:
Originally Posted by Telos View Post
Code:
select u.user_id from users u
You don't need to use the table alias until after you declare it.
Code:
select u.user_id from users u
would give you the same result as
Code:
select user_id from users u
but after you've declared a table alias you must use that in the rest of the query. In other words
Code:
select user_id from users u
order by u.user_id
would work, but
Code:
select user_id from users u
order by users.user_id
would give you a syntax error. (1109 - Unknown table 'users' in order clause)
__________________


Religion: It's all fun and games until someone gets burned at the stake...
tamlin is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old 02-15-2008   #6 (permalink)
Janitor of Lunacy
 
tamlin's Avatar
 
Join Date: May 2006
Location: Sitting in the Wishing Chair
Posts: 4,829

In answer to your first question:
Quote:
I just don't know how to get the values that I need from joining the tables
you'll need to use Aggregate Functions. Here's a couple of links to get you started:
Roland Bouman's blog: Powerful MySQL Aggregate Functions
MySQL Tutorial - Group By

In answer to your second question:
Quote:
Another small problem I am having is deciding if I am going to use a for or do...while loop to display the data
it doesn't really matter. Both will give you the result you require and both are equally efficient. Some (very pedantic) programmers might argue that WHILE implies a value that may vary, but either will work just as well as the other. Just use whatever you feel most comfortable with.
__________________


Religion: It's all fun and games until someone gets burned at the stake...

Last edited by tamlin; 02-15-2008 at 09:08 AM.
tamlin is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
im confused Mishelly Battles System Discussion 9 07-04-2007 02:32 AM
For Confused Minds: What Are Vector Graphics? Jonathan Hue Illustration, Sketching & Vector Art 4 05-25-2007 11:11 AM
Someone Join the Cold War Battle rau89 Battles System Discussion 0 02-25-2007 08:48 PM
Never Ever Join A Gaming Clan supafly General Discussions 5 02-23-2005 10:02 AM
Slightly Confused?! IndigoRose BioRUST Specific Threads 5 02-09-2005 09:33 PM


All times are GMT +1. The time now is 09:37 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2007 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT