我有一个mysql数据库,我需要它的内容的rss提要。 我需要这在JSON等价的:从json的mysql结果
mysql_select_db("mydb", $con);
$result = mysql_query("select date, title, description, url from blah where type = 'OFFERS' order by ref desc");
echo '<?xml version="1.0"?>
<rss version="2.0">
<channel>
<title></title>
<description></description>
<link></link>';
while($row = mysql_fetch_array($result))
{
echo "
<item>
<title>" . $row['title'] . "</title>
<description>" . $row['description'] . "</description>
<link>" . $row['url'] . "</link>
<image>" . $row['date'] . "</image>
</item>";
}
到目前为止,我能得到的工作最接近的事是这样的:
<?php
$host="localhost";
$username="username";
$password="password";
$db_name="mydb";
$con=mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "select date, title, description, url from blah where type = 'OFFERS' order by ref desc";
$result = mysql_query($sql);
$json = array();
if(mysql_num_rows($result)){
while($row=mysql_fetch_row($result)){
$json['title'][]=$row;
}
}
mysql_close($db_name);
echo json_encode($json);
?>
任何帮助,将不胜感激
完美。谢谢你的帮助 – 2012-03-30 10:56:40