You are here: Problem with select-join query (Was: Att: J.O Aho) « All PHP « IT news, forums, messages
Problem with select-join query (Was: Att: J.O Aho)

Posted by J.O. Aho on 01/12/07 13:25

Dave Nash wrote:
> select i.itemid, i.itemname, i.attachment, i.price, i.itemcode
> from items i join ItemCat ic on i.itemid = ic.itemid where ic.catid =
> $catid
>
> But when ive gone from my local server to live I come up with the
> following error
>
> #1064 - You have an error in your SQL syntax near 'on i . itemid = ic
> . itemid where ic . catid = '40' LIMIT 0, 30 ' at line 1

I would think the error could be in "ItemCat ic", you should use AS if you
"rename" a table in your query

SELECT i.itemid, i.itemname, i.attachment, i.price, i.itemcode
FROM items AS i JOIN ItemCat AS ic ON i.itemid = ic.itemid WHERE ic.catid =
$catid

I usually use capital letters on sql functions, IMHO it makes things a little
bit more easy to read when you know what belongs together with what, usage of
parentheses can sometimes make the query easier to read.

MySQL at least shows the code that comes directly after the error, of course
it had been easier if the error text could be more straight forward.


Added alt.php.sql to the newsgroups, as it's in my opinion a more proper
newsgroup and changed the topic name to cover the what the problem is about.

--

//Aho

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация