Javascript 某些rss字段在rss中显示为未定义
我用javascript编写了以下代码,用于显示rss:Javascript 某些rss字段在rss中显示为未定义,javascript,php,rss,undefined,elements,Javascript,Php,Rss,Undefined,Elements,我用javascript编写了以下代码,用于显示rss: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>jQuery RSS Reader</title> <link rel="stylesheet" type="text
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>jQuery RSS Reader</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script type="text/javascript" src="js/jquery.jfeed.pack.js"></script>
<script type="text/javascript" src="js/jquery.flips.min.js"></script>
<script type="text/javascript">
jQuery(function() {
jQuery.getFeed({
url: 'last_20_reports.php',
success: function(feed) {
var html = '';
for(var i = 0; i < feed.items.length && i < 20; i++) {
var item = feed.items[i];
html += "<div class='block'>"
// Gets the RSS link and title
+ '<h3>' + item.title + '</h3>';
html += item.description + '<br><br>';// Gets the RSS description
html += "<div class='grey'>"
// Gets the RSS pubDate
+ 'από ' + item.author +'<br>'
+ 'στις ' + item.updated
+ '</div>';
// Gets the RSS category
//html += item.category
html += '</div>';
}
jQuery('#latestnews').append(html);
// Adds the jQuery Flips element. The direction can left, top or bottom/
$('#news').flips( { autorun_delay:1000, direction: 'right'});
}
});
});
</script>
</head>
<body>
<div class="to-flips" id="news">
<h1>Πρόσφατες αναφορές</h1>
<div class="content">
<div id="latestnews"></div>
</div>
<div class="flipnav"></div>
</div>
</body>
</html>
jQuery RSS阅读器
jQuery(函数(){
jQuery.getFeed({
url:'last_20_reports.php',
成功:功能(提要){
var html='';
对于(变量i=0;i
';//获取RSS描述
html+=“”
//获取RSS发布日期
+“από”+item.author+“
”
+“στις”+项目更新
+ '';
//获取RSS类别
//html+=item.category
html+='';
}
jQuery('#latestnews').append(html);
//添加jQuery翻转元素。方向可以是左、上或下/
$(“#新闻”).flips({autorun#u delay:1000,direction:'right'});
}
});
});
Πρόσφατες αναφορές
并显示每个项目的元素标题和说明,但作者和类别显示为未定义。你能帮我吗
xml“文件”(last_20_reports.php)是:
提前谢谢,对不起我的英语
”
应该是”
。哦,是的,我没有注意到,但它仍然有效。。谢谢!:)我看到您使用了msql\u fetch\u array()
。您应该使用mysqli
。面向对象的方法也受到青睐。如$db=newmysqli(/*args here*/)$res=$db->query(/*queryhere*/);如果($res->num_rows>0){while($row=$res->fetch_assoc()){/*while stuff here*/}$res->free()$db->close()代码>。我会使用$res->fetch_object()代码>,我自己。那可能还不是你的问题。首先,我们仍然没有看到数据库连接。我们需要看到更多的代码。确保数据库连接位于单独的“确定”页面上。不要向我们展示你是如何得到$result
的。我对网络编程是新手,所以我不知道如何使用msqli:/。当我完成学校的这个项目时,我会进一步研究;)数据库连接工作,因为它显示标题、描述和发布日期。我会发布我的全部代码。谢谢!您不能使用msql
,它已被折旧。相信我,在面向对象的方法上。它省去了打字。也许您想使用PDO,但我使用的是mysqli
。请参阅本页上的示例。就像它字面上用紫色写的示例
。
<?php
header ("Content-Type: application/xml;");
$db_host = "***";
$db_username = "***";
$db_pass = "***";
$db_name = "dhmos_patras_db";
$con = mysql_connect("$db_host","$db_username","$db_pass") or die ("Could not connect to mysql");
$sel = mysql_select_db("$db_name") or die ("No database");
$sql = "SELECT * FROM reports INNER JOIN categories ON reports.categoryID = categories.categoryID INNER JOIN members ON reports.userID = members.memberID ORDER BY submit_date DESC LIMIT 0, 20";
$result = mysql_query ($sql,$con);
//xml
echo '<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<feed xmlns="http://www.w3.org/2005/Atom">';
echo '<channel> ';
while($row = mysql_fetch_array($result))
{
echo '<item>';
echo '<title>'.$row['title'].'</title>';
echo '<description>'.$row['description'].'</description>';
echo '<pubDate>'.$row['submit_date'].'</pubDate>';
echo '<category>'. $row['category_name'] .'</category>';
echo '<author>'. $row['username'] .'</author>';
echo '</item>';
}
echo '</channel>';
echo '</feed>';
echo '</rss>';
?>