Reputation: 4951
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;
?>
Upvotes: 0
Views: 216
Reputation: 1054
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
Upvotes: 0
Reputation: 2339
Limit you SQL query
$query = "SELECT * FROM rss_eng LIMIT 6"
Upvotes: 1