?

Search Help Board

PHP FAQ
PHP Articles
PHP Help
Bulletin Board

PHP Manual (NEW!)
First Time PHP'ers
Help with programming
Sql assignment help
PHP Homework Help


C# Help

?
?Pull from SQL database
Author:??(---.nyc.rr.com)
Date:???01-09-04 08:09

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
------------------------

Can someone help me covert it to SQL?

?Re: Pull from SQL database
Author:??(66.62.43.---)
Date:???01-09-04 10:04

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.

?Re: Pull from SQL database
Author:??(---.nyc.rr.com)
Date:???01-11-04 11:36



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.

Bit, I plug in the variables, it gets stuck.

?Re: Pull from SQL database
Author:??(209.250.16.---)
Date:???01-11-04 12:09

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

Check the quotes.

Go to Top??|??Go to Topic??|??Threaded View??|??Search?
??|??
New Topic
?Reply To This Message
?Your Name:
?Your Email:
?Subject:
Email replies to this thread, to the address above.
??

Provided By
Phorum