RE: [PHP-DB] NEWBIE - Needs Assistance with Joins
| From: | Cecily Walker | Date: | Mon, 17 Sep 2001 21:09:53 +0000 |
| Subject: | RE: [PHP-DB] NEWBIE - Needs Assistance with Joins | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-12526@lists.php.net to get a copy of this message | ||
Thanks for the assistance everyone. I'll give all the suggestions a try and report back.
From: "Remo Pini" <remo.pini@pini.org> To: <php-db@lists.php.net>, "Cecily Walker Kidd" <babeephat@hotmail.com> Subject: RE: [PHP-DB] NEWBIE - Needs Assistance with Joins Date: Mon, 17 Sep 2001 22:27:59 +0200 actually artist_id = 'aid' will not work, since you are comparing artist_id with the string "aid" and not with the artists id in the second table... from a sql point of view the statement SELECT artist_name, album_title FROM artists, album_titles WHERE artist_id = aid is correct (if your names are UNIQUE and correct and if you only want 1:1 relations). For starters you could write the statement as one of the following: SELECT artists.artist_name, album_titles.album_title FROM artists LEFT JOIN album_titles ON artists.artist_id = album_titles.aid (might be RIGHT JOIN, I'm never sure...) or if everything is unique: SELECT artist_name, album_title FROM artists LEFT JOIN album_titles ON artist_id = aid Greets, Remo -----Original Message----- From: Jason Wong [mailto:phplist@gremlins.com.hk] Sent: Monday, September 17, 2001 10:10 PM To: php-db@lists.php.net; Cecily Walker Kidd Subject: Re: [PHP-DB] NEWBIE - Needs Assistance with Joins ----- Original Message ----- From: Cecily Walker Kidd <babeephat@hotmail.com> To: <php-db@lists.php.net> Sent: Monday, September 17, 2001 5:42 AM Subject: [PHP-DB] NEWBIE - Needs Assistance with Joins_________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.aspHello, I have two tables, one that contains an item id, album title name, and artist ID number. The second table is a list of artists, with an auto-increment artist ID. I want to join the two tables and have them output to a single PHPpage.I was following along with the tutorial at http://www.webmasterbase.com/article/228/, and tried to modify it formyown needs. When I do this, I get a parse error on the line thatstartswith SELECT. Here's the code: $Link = mysql_connect ($Host, $User, $Password); $CDList =mysql_query( "SELECT artist_name, album_title ". "FROM artists, album_titles WHERE artist_id = aid"); What am I doing wrong? Thanks in advance.Try: -------------------------------------------------------- $CDList = mysql_query("SELECT artist_name, album_titleFROM artists, album_titles WHERE artist_id = 'aid'" );-------------------------------------------------------- hth -- Jason Wong Gremlins Associates www.gremlins.com.hk Tel: +852-2573-5033 Fax: +852-2573-5851 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net For additional commands, e-mail: php-db-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net