【问题标题】:how do i define a constant in a string in PHP?如何在 PHP 中的字符串中定义常量?
【发布时间】:2010-09-07 20:12:59
【问题描述】:

我正在使用常量NEWS_POST_NUMBER,我对如何将其附加到字符串以将其查询到数据库感到困惑。我尝试了很多东西,但它给出了错误。

这是我试过的字符串。

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

请注意NEWS_POST_NUMBER是我定义的常量我想附加它来查询我该怎么做?

【问题讨论】:

标签: php string constants


【解决方案1】:
$query = "SELECT news.id, news.timestamp, news.title FROM news ORDER BY id DESC LIMIT $from, " . NEWS_POST_NUMBER;

使用concatenation operator ;)

【讨论】:

    【解决方案2】:
    $query = "
    SELECT news.id, news.timestamp, news.title 
    FROM news 
    ORDER BY id DESC 
    LIMIT $from, " . NEWS_POST_NUMBER;
    

    【讨论】:

      猜你喜欢
      • 2011-11-27
      • 2012-03-27
      • 2011-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 2018-11-17
      相关资源
      最近更新 更多