NYCPHP Meetup

NYPHP.org

[nycphp-talk] Re: newbie question/confusion

Faber Fedor faber at linuxnj.com
Tue Feb 22 23:27:32 EST 2005


On 22/02/05 23:10 -0500, Freeman, Joshua wrote:
> I am at a complete and total loss as to how to edit my code at this
> point so that, before displaying anything, i can grab either
> 'state_abbr' or 'state_name' from the states table, properly
> associated with the 'state_id' and display the actual state
> abbreviation or state name in my web page.

Are you asking "how do I do a JOIN on the tables"?

SELECT botgard_name, botgard_address,
yadayadayada, state_abbr
FROM gardens LEFT JOIN states 
ON gardens.state_id = states.state_id

(I think that's the syntx) or, to be safer, you might want to do

SELECT botgard_name, botgard_address,
yadayadayada, state_abbr
FROM gardens, states
WHERE gardens.state_id = states.state_id

(I know that syntax will work). There are subtle differences between the
two, but either should work in your circumstance.

You want to RTFM at http://dev.mysql.com/doc/mysql/en/join.html which
isn't too helpful, IMO, or try
http://www.devshed.com/c/a/MySQL/MySQL-Table-Joins/

-- 
 
Regards,
 
Faber                     

Linux New Jersey: Open Source Solutions for New Jersey
http://www.linuxnj.com






More information about the talk mailing list