Forum Moderators: coopster

Message Too Old, No Replies

error in your SQL syntax

         

dwighty

10:03 am on May 11, 2006 (gmt 0)

10+ Year Member



Hi Guys,

Just wandering if someone could point out the mistake, thanks.

While executing query "SELECT t.topicid, t.topicimage, t.topictext, count(s.sid) AS stories, SUM(s.counter) AS reads FROM cms_topics t LEFT JOIN cms_stories s ON (s.topic = t.topicid) GROUP BY t.topicid, t.topicimage, t.topictext ORDER BY t.topictext"

the following error occured: You have an error in your SQL syntax; check the right syntax to use near 'reads FROM cms_topics t LEFT JOIN cms_stories s ON (s.topic = t In: /******************/modules/Topics/index.php on line: 22

Thanks in advance

omoutop

10:11 am on May 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try this:

SELECT ...
FROM cms_topics t, cms_stories s
WHERE s.topic = t.topicid ...

dwighty

10:38 am on May 11, 2006 (gmt 0)

10+ Year Member



omoutop,

Thanks for your quick reply. I have tried the following but still getting an error.

$result = $db->sql_query('SELECT t.topicid, t.topicimage, t.topictext, count(s.sid) AS stories, SUM(s.counter) AS reads
FROM '.$prefix.'_topics t, '.$prefix.'_stories s WHERE s.topic = t.topicid
GROUP BY t.topicid, t.topicimage, t.topictext ORDER BY t.topictext',false, __FILE__, __LINE__);

/* and */

$result2 = $db->sql_query('SELECT s.sid, s.catid, s.title, c.title AS cat_title FROM '.$prefix.'_stories s, '.$prefix."_stories_cat c WHERE s.catid=c.catid
WHERE s.topic='$topicid' ORDER BY s.sid DESC LIMIT 0,10",false, __FILE__, __LINE__);

/* Error Msg */
CMS Warning line 51: On /index.php?name=Topics While executing query "SELECT t.topicid, t.topicimage, t.topictext, count(s.sid) AS stories, SUM(s.counter) AS reads FROM cms_topics t, cms_stories s WHERE s.topic = t.topicid GROUP BY t.topicid, t.topicimage, t.topictext ORDER BY t.topictext" the following error occured: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'reads FROM cms_topics t, cms_stories s WHERE s.topic = t.topici In: /******/modules/Topics/index.php on line: 22

Have I mis-understood what you were suggesting?

omoutop

11:14 am on May 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



no u understood correclty...

perhaps changing the "reads" into something else? possible a restrict word?

since i am no expert in sql, check if u can use the SUM with the GROUP BY also - never thought of using these two together :)

other than that i cant advice any further. Your sql seems correct

dwighty

1:02 pm on May 11, 2006 (gmt 0)

10+ Year Member



omoutop,

Thanks for trying. As far as i am aware the syntax should work together.

Dwighty

coopster

2:31 pm on May 11, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



reads
is a reserved [dev.mysql.com] word.