rocky48 Posted December 22, 2014 Share Posted December 22, 2014 I have got a set of data for a country for each week of the year, but want to display the data a quarter at a time, using a form which posts a value into LIMIT, which was OK for the 1st quarter, but for subsequent quarters I needed to use LIMIT in the form LIMIT start, rows. I found by experiment that this had to be the last statement in the query. when I added the start I got an error: Parse error: syntax error, unexpected ',' in /homepages/43/d344817611/htdocs/Admin/Visitdata.php on line 10 Here is the SQL part of my code: $Visit_data="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country=Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '".$_POST["Country"]."' ORDER BY ctryvisits.WNo LIMIT '".$_POST["QUARTER"]."'" - 13, '".$_POST["QUARTER"]."'"; Is this the best way of doing what I require or is there an easier way of achieving what I want? Quote Link to comment Share on other sites More sharing options...
requinix Posted December 22, 2014 Share Posted December 22, 2014 Have you noticed that the forum adds syntax highlighting to code? Makes it easier to spot syntax errors like, say, getting quotes mixed up. Quote Link to comment Share on other sites More sharing options...
Solution Psycho Posted December 22, 2014 Solution Share Posted December 22, 2014 Also, when defining strings with variables, I prefer to use the double-quotes (as you have done) and include the variables {inside} the quoted string. Always going in and out of the quotes and concatenating content makes it harder to see these errors. Also, how you are defining the limit value doesn't look correct. It looks like you are putting the numerical values in quotes and also trying to do a subtraction. These should not be in quotes. You could probably do the subtraction, but would probably want to put it in parenthesis. But, I would do the match before creating the query. $limitStart = $_POST['QUARTER'] - 13; $query="SELECT WeekNo.WNo, WeekNo.WCom, Countries.Country, ctryvisits.CVisits FROM ctryvisits LEFT JOIN Countries ON ctryvisits.country = Countries.CID LEFT JOIN WeekNo ON ctryvisits.WNo=WeekNo.WNo WHERE Countries.Country = '{$_POST['Country']}' ORDER BY ctryvisits.WNo LIMIT {$limitStart}, {$_POST['QUARTER']}"; By the way, this is wide open to SQL Injection. Definitely look into prepared statements. Quote Link to comment Share on other sites More sharing options...
rocky48 Posted December 24, 2014 Author Share Posted December 24, 2014 Thanks for the help! I did change the rows part to 13, as when I choose 2nd and 3rd quarter the rest of the year data. 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.