TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-12-2008, 10:35 PM   #1 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
TerrorRonin is on a distinguished road
Default Need some help with SQL Join... Cant seem to come up witha working solution

The problem:
Table `games` has the fields `genre`, `publisher`, `developer` which contains `id`s to repsective tables `genres`, `publishers`, and `developers`. I need to create a JOIN (I believe it's an INNER because both need to have values and should have values) that merges the the ids into the respective names.

Example: $game['genre'] now will represent 'Volcom', because the replace $game['genre'] pulled up the `genres` table and found Volcom to match the `id`
TerrorRonin is offline  
Reply With Quote
Old 11-13-2008, 02:16 AM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Is this just a case of adding unique names? Such as like in the following example:

sql Code:
SELECT
    myTable1.myColumn1 AS MyCol1,
    myTable2.myColumn1 AS MyCol2
FROM
    myTable1
INNER JOIN
    ...
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 11-13-2008, 10:34 AM   #3 (permalink)
The Contributor
 
Join Date: Dec 2007
Posts: 31
Thanks: 0
TerrorRonin is on a distinguished road
Default

Well, the data inside of the tables looks like this

Code:
`games`
-- `name` (Halo 3)
-- `genre` (1)
-- `developer` (4)
-- `publisher` (3)
-- ...

`developers`
-- `id` (4)
-- `name` (Bungie)
...

`publishers`
-- `id` (3)
-- `name` (Microsoft)
...

`genres`
-- `id` (1)
-- `name` (First Person Shooter)
And after i've pulled the data, I want to have this come from my fetch_array

$game['name'] = Halo 3
$game['genre'] = First Person Shooter
$game['publisher'] = Microsoft
$game['developer'] = Bungie

Make sense? So what would the MySQL query be for that?
TerrorRonin is offline  
Reply With Quote
Old 11-15-2008, 04:27 AM   #4 (permalink)
The Addict
 
sarmenhb's Avatar
 
Join Date: Jan 2008
Location: los angeles
Posts: 309
Thanks: 44
sarmenhb is on a distinguished road
Default

the format is

select column from table1 inner join table2 on table1.column=table2.column (where table1.column = ....)

the stuff in the parenthesis is optional
__________________
no signature set
sarmenhb is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 08:55 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design