PDA

View Full Version : Using LEFT JOIN


KTBleeding
07-02-2005, 02:20 PM
Hey guys, I'm in need of a little help.
I'm making a php based site for a record label and I can't seem to get this function working correctly.

I need to display the bands discography when viewing a bands profile page. I thought using LEFT JOIN would get this, and I'm still sure it will but I am obviously doing it wrong.

The code I'm using for the function is:

function bandreleases()
{
$query = "SELECT * FROM releases LEFT JOIN bands WHERE releases.bandtitle=bands.title ORDER BY id DESC";
$result = mysql_query($query);
while ($release = mysql_fetch_array($result))
{
print "<strong>$release[title]</strong><br /><img src=\"themes/bandwebsite/images/releases/$release[bandtitle]_125.jpg\" border=\"0\" />";
}
}


And I get the following error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/********/public_html/test/functions.php on line 64

Any help will be greatly appreciated.
- Thanks

EDIT! I got it working.. I used INNER JOIN instead, and used the "ON" rather than "WHERE"..

sabret00the
07-02-2005, 04:40 PM
change your query to this and it'll start working.
SELECT *
FROM releases
LEFT JOIN bands ON (releases.bandtitle = bands.title)
ORDER BY releases.id DESC