how to add different images in my rss feed using php

…衆ロ難τιáo~ 提交于 2019-12-12 02:45:58

问题


i want to add images dynamically in my rss feed but its only showing thumbs then it disappear see the sample here

my images are stored on my server at a folder called "allimages" and all pages are retrieved from mysql database. where em i wrong!!!?

Any help ll be appreciated thaanx below is my code

 <?php
header("Content-type: text/xml");
$connection = mysql_connect( "------", "-----", "-----");
mysql_select_db("-------", $connection);
$sundo = "SELECT * FROM NEWSPAGES ORDER BY ID DESC LIMIT 20";
$query = mysql_query($sundo ) or die(mysql_error());

echo (" <rss version=\"2.0\"> ");
echo (" <channel> ");
echo (" <title>People</title>");
echo (" <link>http://tabata.com</link>");
echo (" <description>tabata</description> ");
echo " <copyright>Copyright 2013</copyright> \ n";
echo " <managingEditor>tabata(sun)</managingEditor> \ n";
echo " <webMaster>tabata.com (sun)</webMaster> \ n";
echo (" <language>IT- en</language>");
while($array = mysql_fetch_array( $query )) {
extract($array);
echo "<item>
<title>$title</title>
<link>http://tabata.com/news.php?page=$id</link>
<description><![CDATA[<img src=\"http://tabata.com/$allimages\" width=\"57\" height=\"57\" />]]>$description</description>
<image>
<link>http://tabata.com/news.php?page=$id</link>
<url>http://tabata.com/$allimages</url>
<title>$title</title>
</image>
</item>";
}
echo " </channel> </rss>" ;

?>


回答1:


First of all, your code becomes quite unreadable because you use SELECT * and extract(). You could better replace them with SELECT field1, field2, etc and I suggest avoiding the extract() function all-time, you suggest you'd use something like $field1 = $array['field1'].

Then it should be easier to find out if the field allimages exists in your query result. Test each step of the process with print_r() or var_dump() to check if a value contains the expected result.




回答2:


Save image names/full url in you database, create a column of images let say images. Then in you while loop you can get images like $array['images']. Like <image> ... <url>http://tabata.com/$array['images']</url> ... </image> Like for page http://tabelltz.com/news.php?page=31 you image column should have img name 27.jpg and url like <url>http://tabata.com/userfiles/$images</url> I use $images as you're using extract($array); Better if you don't use extract($array);



来源:https://stackoverflow.com/questions/23115259/how-to-add-different-images-in-my-rss-feed-using-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!