Re: left join does not work, why?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Marc Christopher Hall wrote:
> Not to mention if this is written for v 5 then you need to wrap your joins
> in ()
>
> -----Original Message-----
> From: Jan G.B. [mailto:ro0ot.w00t@xxxxxxxxxxxxxx] 
> Sent: Sunday, March 15, 2009 9:47 AM
> To: PJ
> Cc: Daniel Brown; php-general@xxxxxxxxxxxxx
> Subject: Re:  left join does not work, why?
>
> 2009/3/15 PJ <af.gourmet@xxxxxxxxxxxx>:
>   
>> Daniel Brown wrote:
>>     
>>> On Sat, Mar 14, 2009 at 19:51, PJ <af.gourmet@xxxxxxxxxxxx> 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);
>>>>         
>> The error reported now is to check the syntax near the commented out
>>     
> lines.
>   
>> So, what is going on here? I understood that when the lines are
>> commented out they are not lprocessed.
>> When I deleted the commented out lines the errors went away.
>> This does not make sense and obviously could be very misleading in
>> debugging.
>>
>>     
>
> *How* are you commenting out? Mysql accepts /* such comments */, so if
> you want to transform a line in your SQL query string into a comment,
> you gotta do it that way.
> so this is just wrong:
> $x = " select *
> // from foo
> from bar";
> and that query would be valid
> "SELECT this/*, that*/ from x"
>
>   
Quite right...
This has been "mulling" (?) in my mind for a few hours now and I thought
I'd just see what response I would get on the list. O:-)
It took ma a bit of thinking, I must say, but the answer is simple:
You cannot do comment - out's (for that is what this was really about)
within astatement or declaration! I was commenting out two JOINs within
a $sql = "SELECT ...... " declaration that was split into several lines
and it didn't occur to me that you cannot just comment out a part of a
declaration or statement that spans several lines. So, if you comment
out one part the rest will still be parsed. There's a reason, then why
the HTML specification requires that " delimited statements cannot be
split over several lines.  Hope I said all that correctly. :-)

-- 
unheralded genius: "A clean desk is the sign of a dull mind. "
-------------------------------------------------------------
Phil Jourdan --- pj@xxxxxxxxxxxxx
   http://www.ptahhotep.com
   http://www.chiccantine.com/andypantry.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux