Att: J.O Aho

You had given me some help with the following code:

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

PHP + mysql version are different.

Any Ideas???
Dave Nash [ Fr, 12 Januar 2007 03:12 ] [ ID #1593511 ]

Problem with select-join query (Was: Att: J.O Aho)

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
Shion [ Fr, 12 Januar 2007 14:25 ] [ ID #1593559 ]

Problem with select-join query (Was: Att: J.O Aho)

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
Shion [ Fr, 12 Januar 2007 14:25 ] [ ID #1593636 ]
PHP » alt.php » Att: J.O Aho

Vorheriges Thema: htmlentities and single quote
Nächstes Thema: question about changing a string :)