I am converting my site from PHP and a MySQL database, to PHP and a SQL database. In order to do this, I really just need to modify the queries - but I'm having some difficulty. The problem I run into comes from adding the PHP variables to the query (i.e. $botitemnum, $topitemnum). I can get the query to work if I plug in numbers, but once the variables are added, the query errors-out.
PHP Query:
------------------------
SELECT number, section, title, thedate, thedate, year(thedate), text FROM swimnyc_articles WHERE year(thedate)=$theyear ORDER BY thedate DESC LIMIT $botitemnum, $topitemnum
------------------------
You say "SQL" database, but that's not really clear. Do you mean MSSql? If so, LIMIT is not a clause supported by MSSql as far as I know. I would try to output the raw query (set it to a variable then echo the variable) then try that query in the database directly.
I've echo'd out the query and get....
------------------
SELECT number, section, title, thedate, thedate, year(thedate), text FROM swimnyc_articles WHERE year(thedate)=2003 ORDER BY thedate DESC LIMIT 0, 10
------------------
I've also plugged this into the query and it works fine (for the variables were changed to actual numbers.
Are you putting your SQL query into single quotes or doublde quotes? They are different in PHP. Single quotes to not translate variables to values, but double quotes do. So
$id=1;
$sql='select * from people where id = $id';
will actually evaluate to:
select * from people where id = $id
whereas
$sql="select * from people where id = $id";
will evaluate the way you want:
select * from people where id = 1