简体   繁体   English

来自php-mysql的rss feed限制表中的项

[英]rss feed from php-mysql limit items from table

I'm using this code to generate my rss from mysql table, now table I pull rss from it. 我正在使用此代码从mysql表生成我的rss,现在我从该表中提取了rss。 It has so many rows, what I'm trying to modify is only pull the first 6 items only and not the whole rows. 它有很多行,我要修改的只是仅拉前6个项目,而不是整个行。 I used index and break ==6 but still it shows to me all rows. 我使用了index和break == 6,但仍然向我显示了所有行。 Any clues? 有什么线索吗?

Besides I'm trying to echo '#' before each item i pull out and still couldn't get it right. 此外,我尝试在我拔出每个项目之前回显“#”,但仍然无法正确处理。

any tips to fix these 2 thing 任何解决这两个问题的技巧

Regard 看待

<?php
require_once('./config.php');
require_once('dbconnect.php');
header("Content-Type: application/rss+xml; charset=utf-8");

$a=#;

$rssfeed = '<?xml version="1.0" encoding="utf-8"?>';
$rssfeed .= '<rss version="2.0">';
$rssfeed .= '<channel>';
$rssfeed .= '<title>My RSS feed</title>';
$rssfeed .= '<link>http://www.mytest.com</link>';
$rssfeed .= '<description>test.Com RSS</description>';
$rssfeed .= '<language>en-us</language>';
$rssfeed .= '<copyright>Copyright (C) 2012 mytest.com</copyright>';

$query = "SELECT * FROM rss_eng";
$result = mysql_query($query) or die ("Could not execute query");

while($row = mysql_fetch_array($result)) {
    extract($row);
    $index = 0;


    $rssfeed .= '<item>';
    $rssfeed .= '<title>' . $hashtag . '</title>';

    $rssfeed .= '</item>';
}

$rssfeed .= '</channel>';
$rssfeed .= '</rss>';

echo $rssfeed;
$index++;

    if($index==6) break;

 ?>

限制您的SQL查询

$query = "SELECT * FROM rss_eng LIMIT 6"

If you need only 6 rows from table then use LIMIT keyword in your SQL query. 如果您只需要表中的6行,则在SQL查询中使用LIMIT关键字。
SELECT * FROM your_table LIMIT 6;
Other select options for MySQL SELECT you can find here: http://dev.mysql.com/doc/refman/5.0/en/select.html 您可以在此处找到MySQL SELECT的其他选择选项: http : //dev.mysql.com/doc/refman/5.0/en/select.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM