php - 限制sql php中的数据

标签 php mysql sql odbc

This is the code right here. I cant fix this thing. Please help

<?php
$strNewsQuery = '
    SELECT TOP 15
        N.[title],
        C.[title] AS category,
        C.[icon] AS icon,
        N.[datetime],
        N.[forenlink],
        N.[text]
    FROM [' . $_CONFIG['db_databases']['web'] . '].[dbo].[web_news] AS N
        LEFT JOIN [' . $_CONFIG['db_databases']['web'] . '].[dbo].[web_newscategories] AS C ON C.ncatid = N.category
    ORDER BY nid DESC
';
$dbNewsQuery = @odbc_exec($odbc_connect, $strNewsQuery);

if(@odbc_num_rows($dbNewsQuery) > 0) {
    while($mixedNewsEntry = @odbc_fetch_array($dbNewsQuery)) {
        echo '
        <div class="media-box">
            <div class="content-img">
                <span><img height="190px" width="190px" src="images/icons/news/'.$mixedNewsEntry['icon'].'></span>
            </div>
            <div class="con-header">
                ' . $mixedNewsEntry['title'] . '
            </div>
            <div class="content-media">
                    ' . nl2br($mixedNewsEntry['text']) . '
                        ' . $_LANG['publish_date'] . ': ' . date($_CONFIG['web_date_format']['full'], strtotime($mixedNewsEntry['datetime'])) . ' ' . $_LANG['oclock_optional'] . '
            </div>';
        if(!empty($mixedNewsEntry['forenlink'])) {
            echo '
            <div ad-content>
                        ' . $_LANG['news_link_to_forum'] . ': <a href="' . htmlspecialchars($mixedNewsEntry['forenlink']) . '" title="Forum" target="_blank">READ MORE>>></a>.
            </div>';
        }
        echo '
        </div>';
    }
}
else {
    echo createMessage($_LANG['no_entry'], 'hint');
}
?

How can i limit this sql into 5 i tried the "limit 0,5" method at the end of "ORDER BY nid DESC" does not work and tried other methods like java syntax

最佳答案

选择前 15 名更改为选择前 5 名

关于php - 限制sql php中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49381506/

相关文章:

sql - 根据列值对查询中的记录进行分组计数

java - 这个查询可以进行 SQL 注入(inject)吗?

php - 使用 Laravel 插入 created_at 数据

php - 如何使用jquery自动完成从mysql数据库加载数据?

mysql复制跳过语句。可能吗?

mysql - 如何用数据表解决Codeigniter中的搜索问题

php - 如何使用 php 获得像 Google 一样的速度?

php - 在php中显示数组中的部分数据

javascript - 使用 jquery : when active update useronline timestamp on mysql 进入空闲和事件状态的问题

sql - oracle View 和网络流量