Page 1 of 1
fetch articles only from certain catalog in rss.php
Posted: Sat Jan 30, 2016 2:02 pm
by eddie01001
I have a rss.php for my web site which fetch all articles from all catalog and works fine
BUT NOW I want NOT all articles from all catalog I want only catalog " my_catalog_1"
I want fetch all articles from " catalog 1 "
here is my rss.php now (which work fine fetch all articles)
=======================
Code: Select all
<?php
include('connect.php');
$sql = "SELECT * FROM carbon_topics ORDER BY id DESC LIMIT 20";
$query = mysql_query($sql) or die(mysql_error());
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
<title>9lessons | Programming Blog </title>
<link>http://example.com</link>
<description>Programming Blog </description>
<language>en-us</language>";
while($row = mysql_fetch_array($query))
{
$Topic=$row['Topic'];
$ID=$row['ID'];
echo "<item>
<title>$Topic</title>
<link>http://example.com/t/$ID</link>
</item>";
}
echo "</channel></rss>";
?>
=====================
here is my database (this database name is forum_catalog) this is the catalog it contains :" news , questions, help " and now I want only fetch articles from table(forum_catalog) =>news how to done that?

Re: fetch articles only from certain catalog in rss.php
Posted: Sat Jan 30, 2016 3:22 pm
by Celauran
Join your topics table on whatever table is displayed above. The ID in this table is probably a foreign key on the other.
Re: fetch articles only from certain catalog in rss.php
Posted: Sat Jan 30, 2016 4:35 pm
by eddie01001
please tell me how to done it in coding
I am new and learning
really appreciate
Re: fetch articles only from certain catalog in rss.php
Posted: Sat Jan 30, 2016 6:59 pm
by Celauran
I don't have enough information to give you an example. You listed a table with no name and have told us nothing about carbon_topics, though we can see you are querying that also.
Re: fetch articles only from certain catalog in rss.php
Posted: Sat Jan 30, 2016 8:48 pm
by eddie01001
ok I M New to this and I do have a lot things to learn
I have a database named " onesixh3_bbs" and few tables and all the articles are stored in table " carbon_topics" as shown below
http://bbs.168nyc.com/upload/image/2016 ... 548615.png
and another table called " carbon_tags" store all the tags as shown below
in this table it has three tags which are " news, questions, help"
http://bbs.168nyc.com/upload/image/2016 ... 549301.png
NOW my question is how to create a rss feed that only fetch articles from table "carbon_tags" AND select from "news" only I dont want articles from other name
here is what I m thinking join this two tables and select from carbon_tags.news how to coding this ?
thank you so much really appreciate
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 12:27 pm
by eddie01001
here is my three table data
=====================
[text]--
-- Table structure for table `carbon_topics`
--
CREATE TABLE IF NOT EXISTS `carbon_topics` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`Topic` varchar(255) NOT NULL,
`Tags` text,
`UserID` int(10) unsigned NOT NULL DEFAULT '0',
`UserName` varchar(50) NOT NULL,
`LastName` varchar(50) DEFAULT NULL,
`PostTime` int(10) unsigned NOT NULL,
`LastTime` int(10) unsigned NOT NULL,
`IsGood` tinyint(1) unsigned DEFAULT '0',
`IsTop` tinyint(1) unsigned DEFAULT '0',
`IsLocked` tinyint(1) unsigned DEFAULT '0',
`IsDel` tinyint(1) unsigned DEFAULT '0',
`IsVote` tinyint(1) unsigned DEFAULT '0',
`Views` int(10) unsigned DEFAULT '0',
`Replies` int(10) unsigned DEFAULT '0',
`Favorites` int(10) unsigned DEFAULT '0',
`RatingSum` int(10) unsigned NOT NULL DEFAULT '0',
`TotalRatings` int(10) unsigned NOT NULL DEFAULT '0',
`LastViewedTime` int(10) unsigned NOT NULL,
`PostsTableName` int(10) unsigned DEFAULT NULL,
`ThreadStyle` varchar(255) DEFAULT NULL,
`Lists` longtext,
`ListsTime` int(10) unsigned NOT NULL,
`Log` longtext,
PRIMARY KEY (`ID`),
KEY `LastTime` (`LastTime`,`IsDel`),
KEY `UserTopics` (`UserName`,`IsDel`,`LastTime`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
--
-- Table structure for table `carbon_posttags`
--
CREATE TABLE IF NOT EXISTS `carbon_posttags` (
`TagID` int(11) DEFAULT '0',
`TopicID` int(11) DEFAULT '0',
`PostID` int(11) DEFAULT '0',
KEY `TagsIndex` (`TagID`,`TopicID`),
KEY `TopicID` (`TopicID`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--
-- Table structure for table `carbon_tags`
--
CREATE TABLE IF NOT EXISTS `carbon_tags` (
`ID` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL,
`Followers` int(10) unsigned DEFAULT '0',
`Icon` tinyint(1) unsigned DEFAULT '0',
`Description` mediumtext,
`IsEnabled` tinyint(1) unsigned DEFAULT '1',
`TotalPosts` int(10) unsigned DEFAULT '0',
`MostRecentPostTime` int(10) unsigned NOT NULL,
`DateCreated` int(10) unsigned NOT NULL,
PRIMARY KEY (`ID`),
KEY `TagName` (`Name`) USING HASH,
KEY `TotalPosts` (`IsEnabled`,`TotalPosts`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
[/text]
===================================================
I want select topics from table `carbon_topics` AND only certain tag for example "tag1"
here is what I do
$sql = "SELECT carbon_topics.Topic, carbon_topics.ID, carbon_topics.Tags
FROM carbon_topics
WHERE carbon_topics.Tags = 'tag1' ";
i think i failed
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 12:39 pm
by Celauran
Tags being type TEXT is troubling. I would expect to see a relation to an entry in the tags table. What do the contents of that field look like?
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 1:20 pm
by eddie01001
In Table: carbon_topics.Tags has same value as table carbon_tags.name they store the same tag names
and in table carbon_posttags.TagID = carbon_tags.ID
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 1:22 pm
by Celauran
Can a topic not have multiple tags?
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 2:05 pm
by eddie01001
no
why is that a problem?
that true that means Table: carbon_topics.Tags is NOT = carbon_tags.Name
since some topics have 2 or more tags
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 2:16 pm
by eddie01001
in the table carbon_posttags.TagID which is point to each tag's name
we can select from there for example WHERE carbon_posttags.TagID ='1' ;
Re: fetch articles only from certain catalog in rss.php
Posted: Mon Feb 01, 2016 8:47 pm
by eddie01001
Moderator I got it
here is
$sql = "SELECT carbon_topics.ID, carbon_topics.Topic
FROM carbon_topics JOIN carbon_posttags
ON carbon_topics.ID = carbon_posttags.TopicID
WHERE carbon_posttags.TagID='3' ";
another question what I can't view Chinese language I alrady set to zh-cn please help
<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
<title>9lessons | Programming Blog </title>
<link>http://example.com</link>
<description>Programming Blog </description>
<language>zh-CN</language><item>
<title>??????????: ??? ??? ?? ??? ??</title>
<link>
http://example.com/t/3</link>
</item><item>
<title>2015?????????????? ??? ?? ??? ?? ??? ??? ??? ???</title>
<link>
http://example.com/t/4</link>
</item></channel></rss>