简体   繁体   中英

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. It has so many rows, what I'm trying to modify is only pull the first 6 items only and not the whole rows. I used index and break ==6 but still it shows to me all rows. 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.
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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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