Padgoi Posted April 25, 2013 Share Posted April 25, 2013 $q = 'SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `num_rat` FROM `groupcomic` `y` LEFT JOIN `yrat` ON `sid` = `skey` where panels>=3 GROUP BY `sid` ORDER BY `avg` DESC LIMIT 0,5'; This line seems to be causing problems in one of my scripts in that it keeps referring me to this line and saying there is an invalid MYSQL result resource. I'm fairly certain my table structure is off. Can someone please tell me, based on this line, what fields I should have in my table and and what type they should be? I know the table name is groupcomic. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted April 25, 2013 Author Share Posted April 25, 2013 Yeah, it's actually 2 tables, groupcomic and yrat. I ran the query directly in MYSQL and got this error: #1064 - 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 '$q = 'SELECT y.*, (SUM(`rating`)/COUNT(`rating`)) AS `avg`, COUNT(`rating`) AS `' at line 1 I assume it has something to do with the num_rat field but I honestly have no idea. I had that field set up as INT (11). Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 25, 2013 Share Posted April 25, 2013 you would only run the sql part of that statement directly in mysql. the leading $q = ' ... and ending '; are php code, not sql. Quote Link to comment Share on other sites More sharing options...
Padgoi Posted April 25, 2013 Author Share Posted April 25, 2013 Ok, so I did that and got this error: #1064 - 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 ''' at line 1 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted April 25, 2013 Share Posted April 25, 2013 about the only way you could get that error from that sql statement is if you left the leading or trailing php single quote ' on it when you copied/pasted it into mysql to run it. the sql you posted doesn't produce that error for me when i tried it directly in mysql. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.