Re: left join does not work, why?

From: Date: Sat, 14 Mar 2009 23:55:51 +0000
Subject: Re: left join does not work, why?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-290067@lists.php.net to get a copy of this message
On Sat, Mar 14, 2009 at 19:51, PJ <af.gourmet@videotron.ca> wrote: > $sql1 = "SELECT b.id, b.title, b.sub_title, b.descr, b.comment, > b.bk_cover, b.copyright, b.ISBN, b.language, b.sellers, c.publisher, <--- > CONCAT_WS(' ', first_name, last_name) AS Author > FROM book AS b > LEFT JOIN book_author AS ab ON b.id = ab.bookID > LEFT JOIN author AS a ON ab.authID=a.id > LEFT JOIN book_publisher as abc ON b.id = abc.bookID // <--- > LEFT JOIN publishers AS c ON abc.publishers_id = c.id // <--- > ORDER BY title ASC "; > $result1 = mysql_query($sql1, $db); > $bookCount = mysql_num_rows($result1); For this and future problems of a similar nature, the quickest and easiest way to start debugging is to change the mysql_query() line to output the error. Like so: <?php // .... $result1 = mysql_query($sql1,$db) or die("SQL: ".$sql1."\n".mysql_error()); // .... ?> If the query fails on $sql1, PHP runs the 'or' as a failure fallback and dies by printing the SQL query given and MySQL's error response. -- </Daniel P. Brown> daniel.brown@parasane.net || danbrown@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW10000

« previous php.general (#290067) next »