views:

54

answers:

2

Hi,

I am using a constant NEWS_POST_NUMBER and i am getting confused on how to attach it to a string to query it to database. i tried many things and it is giving errors.

here is the string i tried.

$query = "
SELECT news.id, news.timestamp, news.title 
FROM news 
ORDER BY id DESC 
LIMIT $from, NEWS_POST_NUMBER";

please note NEWS_POST_NUMBER is the constant i have defined i want to attach it to query how do i do it?

+2  A: 
$query = "
SELECT news.id, news.timestamp, news.title 
FROM news 
ORDER BY id DESC 
LIMIT $from, " . NEWS_POST_NUMBER;
Tim Cooper
+1 for human-readable formatting
Col. Shrapnel
lol, you are +1 ing for my formatting!!!
Zak
oh, misattributed it. corrected now
Col. Shrapnel
+3  A: 
$query = "SELECT news.id, news.timestamp, news.title FROM news ORDER BY id DESC LIMIT $from, " . NEWS_POST_NUMBER;

Use the concatenation operator ;)

nikic