Skipjackrick Posted February 23, 2009 Share Posted February 23, 2009 I can't figure this one out? Does anything scream out at you guys? 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 'SUM(IF(species_id=1,1,0)) AS speciesA, SUM(IF(angler=1' at line 3 $query_speciestotals = "SELECT angler, species_id, yyyy SUM(IF(species_id=1,1,0)) AS speciesA, SUM(IF(angler=1,1,0)) AS species_total FROM submit WHERE angler=1 GROUP BY species_id AND yyyy ORDER BY yyyy"; $speciestotals = mysql_query($query_speciestotals) or die(mysql_error()); while($row = mysql_fetch_array($speciestotals)) { $yyyy = $row['yyyy']; $speciesA = $row['speciesA']; $species_total = $row['species_total']; $species_totals_row .=<<<EOD <tr> <td align='center'>$yyyy</td> <td align='center'>$speciesA</td> <td align='center'>$species_total</td> </tr> EOD; } Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/ Share on other sites More sharing options...
Skipjackrick Posted February 23, 2009 Author Share Posted February 23, 2009 I know this is against the rules to put a post to the top but i can't edit the post. i forgot to add that the above code is inside a switch statement. i think that's part of it. $queryspecies = "SELECT * FROM submit WHERE angler=$angler_id GROUP BY species_id"; $resultspecies = mysql_query($queryspecies) or die(mysql_error()); // get count of how many rows $rowCount = mysql_num_rows($resultspecies); // let's get the results into an array while($row = mysql_fetch_assoc($resultspecies)) $results[] = $row; switch($rowCount) { case 1: $query_speciestotals = "SELECT angler, species_id, yyyy SUM(IF(species_id=1,1,0)) AS speciesA, SUM(IF(angler=1,1,0)) AS species_total FROM submit WHERE angler=1 GROUP BY species_id AND yyyy ORDER BY yyyy"; $speciestotals = mysql_query($query_speciestotals) or die(mysql_error()); while($row = mysql_fetch_array($speciestotals)) { $yyyy = $row['yyyy']; $speciesA = $row['speciesA']; $species_total = $row['species_total']; $species_totals_row .=<<<EOD <tr> <td align='center'>$yyyy</td> <td align='center'>$speciesA</td> <td align='center'>$species_total</td> </tr> EOD; } more code past this irrelevant Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-768871 Share on other sites More sharing options...
keeps21 Posted February 23, 2009 Share Posted February 23, 2009 Oops - misread your question, sorry. ignore the below. You could try adding '{ }' around $angler_id in your sql $queryspecies = "SELECT * FROM submit WHERE angler='{$angler_id}' GROUP BY species_id"; Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-769150 Share on other sites More sharing options...
Skipjackrick Posted February 23, 2009 Author Share Posted February 23, 2009 Oops - misread your question, sorry. ignore the below. You could try adding '{ }' around $angler_id in your sql $queryspecies = "SELECT * FROM submit WHERE angler='{$angler_id}' GROUP BY species_id"; Nah, its not that... It has something to do with the switch statement I think. switch($rowCount) { case 1: $query_speciestotals = "SELECT angler, species_id, yyyy SUM(IF(species_id=1,1,0)) AS speciesA, SUM(IF(angler=1,1,0)) AS species_total FROM submit WHERE angler=1 GROUP BY species_id AND yyyy ORDER BY yyyy"; $speciestotals = mysql_query($query_speciestotals) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-769473 Share on other sites More sharing options...
PFMaBiSmAd Posted February 23, 2009 Share Posted February 23, 2009 There is no comma after the yyyy to separate it from the next item in the SELECT - angler, species_id, yyyy, Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-769477 Share on other sites More sharing options...
Skipjackrick Posted February 23, 2009 Author Share Posted February 23, 2009 There is no comma after the yyyy to separate it from the next item in the SELECT - angler, species_id, yyyy, AH DARN!!! THANK YOU SO MUCH!! WORKS PERFECT! That's not the first time a comma has got me before... Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-769493 Share on other sites More sharing options...
fenway Posted February 24, 2009 Share Posted February 24, 2009 If you put the commas IN FRONT of your columns, this won't ever happen again. Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-770174 Share on other sites More sharing options...
Skipjackrick Posted February 24, 2009 Author Share Posted February 24, 2009 If you put the commas IN FRONT of your columns, this won't ever happen again. That's a good idea! Do you know of a good site for formatting code? Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-770315 Share on other sites More sharing options...
fenway Posted February 25, 2009 Share Posted February 25, 2009 Not sure exactly what you mean by that... since you're writing it, why not write it properly at the get-go? But this tool is handy when reviewing old/other ppl's code. Quote Link to comment https://forums.phpfreaks.com/topic/146448-solved-syntax-error/#findComment-770819 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.