cyberkiller Posted May 13, 2007 Share Posted May 13, 2007 I wrote a small script that will output information to an rss file. It worked fine, however I modified it to output to a randomly named file. Upon running the script it outputs two random files instead of just one. I've narrowed it down and for some reason its the while loop causing the problem. Not sure why though. The table im using just has three fields, id title date where id is auto incrementing. <?php $link = mysql_connect('server', 'user', 'pw') or die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('database') or die('Could not select database'); $xmldate = date("r"); $query="SELECT * FROM rss order by 'id' desc limit 0,100"; $result=mysql_query($query); $body="<?xml version=\"1.0\" encoding=\"UTF-8\"?> <rss version=\"2.0\"> <channel> <title>My Site</title> <link>http://www.mydomain.com</link> <description>My Description</description> <copyright>(c)</copyright>"; $i=0; while ($i < 100) { $title=mysql_result($result,$i,"title"); $body .=" <item> <title>$title</title> <link>http://www.mysite.com</link> <description><![CDATA[ my description ]]></description> <pubDate>$xmldate</pubDate> </item>"; $i++; } $body .=" </channel> </rss>"; echo $body; $ran=rand(); $path=$ran.".xml"; $filenum=fopen($path,"w"); fwrite($filenum,$body); fclose($filenum); mysql_close($link); ?> Link to comment https://forums.phpfreaks.com/topic/51224-script-outputs-file-twice-not-sure-why/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.