代码之家  ›  专栏  ›  技术社区  ›  noobzilla

cffeed问题

  •  0
  • noobzilla  · 技术社区  · 15 年前

    是的,我在一个有几个不同的RSS源的网站上工作。我的问题是我的一个提要工作得很好,但是第二个提要(基于几乎相同的代码)失败了,我不知道为什么。

    这是有效的代码:

    <!--- Get the feed data as a query from the orders table. ---> 
    <cfquery name="getNews" datasource="#DSN#">  
        SELECT * FROM NEWS2
        WHERE STATUS = 1 
        ORDER BY rdate DESC
    </cfquery>  
    
    
    <cfset myStruct = StructNew() />
    <cfset mystruct.link = "http://noobzilla.net" />
    <cfset myStruct.title = "Noobzilla News" />
    <cfset mystruct.description = "Programming Related Site Reviews" />
    <cfset mystruct.pubDate = Now() />
    <cfset mystruct.version = "rss_2.0" />
    <cfset myStruct.item = ArrayNew(1) />
    
    <cfloop query="getNews">
        <cfset myStruct.item[currentRow] = StructNew() />
        <cfset myStruct.item[currentRow].guid = structNew() />
        <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
        <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail.cfm?id=#id#' />    
        <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
        <!---<cfset myStruct.item[currentRow].title = xmlFormat(title) />--->
        <cfset myStruct.item[currentRow].title = #title# />
        <cfset myStruct.item[currentRow].description = StructNew() />
        <!---<cfset myStruct.item[currentRow].description.value = xmlFormat(#info#) />--->
        <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
        <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail.cfm?id=#id#' />
    </cfloop>
    
    <!--- Generate the feed and save it to a variable. --->
    <cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />
    

    上面的代码工作得很好。下面是我的第二个文件中的代码(您可以看到它实际上是相同的,只是使用了一个不同的表):

    <!--- Get the feed data as a query from the orders table. ---> 
    <cfquery name="getNews" datasource="#DSN#">  
        SELECT * FROM NEWS
        WHERE STATUS = 1 
        ORDER BY rdate DESC
    </cfquery> 
    
    <cfset myStruct = StructNew() />
    <cfset mystruct.link = "http://noobzilla.net" />
        <cfset myStruct.title = "IDE Reviews" />
    <cfset mystruct.description = "IDE and SDK Reviews" />
    <cfset mystruct.pubDate = Now() />
    <cfset mystruct.version = "rss_2.0" />
    <cfset myStruct.item = ArrayNew(1) />
    
    <cfloop query="getNews">
        <cfset myStruct.item[currentRow] = StructNew() />
        <cfset myStruct.item[currentRow].guid = structNew() />
        <cfset myStruct.item[currentRow].guid.isPermaLink="YES" />
        <cfset myStruct.item[currentRow].guid.value = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />    
        <cfset myStruct.item[currentRow].pubDate = "#DateFormat(getNews.rdate, "mm/dd/yyyy")#" />
        <cfset myStruct.item[currentRow].title = #title# />
        <cfset myStruct.item[currentRow].description = StructNew() />
        <cfset myStruct.item[currentRow].description.value = '#Left(info, 250)#...' />
        <cfset myStruct.item[currentRow].link = 'http://noobzilla.net/news-detail2.cfm?id=#id#' />
    </cfloop>
    
    <!--- Generate the feed and save it to a variable. --->
    <cffeed action="create" name="#myStruct#" overwrite="true" xmlVar="myXML" />
    

    第二组代码生成以下错误:

    分析pubdate中指定的日期时出错。 无法将PubDate转换为日期。

    3 回复  |  直到 15 年前
        1
  •  2
  •   Pragnesh Vaghela    15 年前

    我会检查getnews.rdate值,并确保它是ColdFusion接受的任何标准日期或日期/时间格式。

        2
  •  1
  •   Sergey Galashyn    15 年前

    这是Pragnesh提出的解决方案的代码示例:

    <cfif isDate(getNews.rdate)>
        <cfset myStruct.item[currentRow].pubDate = DateFormat(getNews.rdate, "mm/dd/yyyy") />
    <cfelse>
        <cfset myStruct.item[currentRow].pubDate = DateFormat(Now(), "mm/dd/yyyy") />
    </cfig>
    
        3
  •  0
  •   noobzilla    15 年前

    Ben,Sergii和Pragnesh-谢谢你的回复。我有时会有点迟钝。我发现这个错误一定是由第一行引起的:

    我根据你的建议仔细检查了我的数据,结果发现这是一个没有数据的记录。

    干杯!

    推荐文章