rilana Posted August 22, 2008 Share Posted August 22, 2008 Hello all, I am trying to do a News Script in Flash using PHP, xml and a mySql-Database. So far I am still stuck at getting the xml in the right format. I get this <?xml version="1.0"?> <news> <item>Sommercheck und Frischluft Service!</item> <item>Geniessen Sie die warmen Jahreszeiten und profitieren Sie von unserem Gratis-Klimaanlagecheck und viel mehr!</item> <item>http://www.rilana.biz</item> <item>Neues Ford-Zubehör</item> <item>Bla Bla Bla</item> <item>das ist ein url</item> </news> unstead of this <?xml version="1.0"?> <news> <item> <titel>Sommercheck und Frischluft Service!</titel> <text>Geniessen Sie die warmen Jahreszeiten und profitieren Sie von unserem Gratis-Klimaanlagecheck und viel mehr!</text> <link>http://www.rilana.biz</link> </item> </news> my php code to do this looks like this: while($line = mysql_fetch_assoc($results)) { echo "<item>" . $line["titel"] . "</item>\n"; echo "<item>" . $line["text"] . "</item>\n"; echo "<item>" . $line["link"] . "</item>\n"; } I tryed to change it and put my text and link in between the item's, but I always get errors and I have no clue how to write it out right. I realy would aprechiate some help or hints.. thank you verry much, Rilana Link to comment https://forums.phpfreaks.com/topic/120885-solved-turning-mysql-data-into-xml-with-php/ Share on other sites More sharing options...
Demonic Posted August 22, 2008 Share Posted August 22, 2008 echo "<item>" . $line["titel"] . "</item>\n"; echo "<item>" . $line["text"] . "</item>\n"; echo "<item>" . $line["link"] . "</item>\n"; Should be: echo "<item>\n"; echo "<title>" . $line["titel"] . "</title>\n"; echo "<text>" . $line["text"] . "</text>\n"; echo "<url>" . $line["link"] . "</url>\n"; echo "</item>\n"; Link to comment https://forums.phpfreaks.com/topic/120885-solved-turning-mysql-data-into-xml-with-php/#findComment-623128 Share on other sites More sharing options...
Mchl Posted August 22, 2008 Share Posted August 22, 2008 Or: echo "<item>\n"; echo "<title>{$line["titel"]}</title>\n"; echo "<text>{$line["text"]}</text>\n"; echo "<url>{$line["link"]}</url>\n"; echo "</item>\n"; And last but not least, there are specialised functions for XML output. For example: http://www.php.net/manual/en/book.xmlwriter.php Link to comment https://forums.phpfreaks.com/topic/120885-solved-turning-mysql-data-into-xml-with-php/#findComment-623167 Share on other sites More sharing options...
Barand Posted August 22, 2008 Share Posted August 22, 2008 Here's a general-purpose function <?php function sql2xml ($sql, $root = 'root') { $res = mysql_query($sql); $xml = "<?xml version=\"1.0\"?>\n<$root>\n"; while ($row = mysql_fetch_assoc($res)) { $xml .= "<item>\n"; foreach ($row as $k=>$v) { $xml .= "\t<$k>$v</$k>\n"; } $xml .= "</item>\n"; } $xml .= "</$root>"; return $xml; } $sql = "SELECT * FROM mytablename"; echo sql2xml($sql, 'news'); ?> Link to comment https://forums.phpfreaks.com/topic/120885-solved-turning-mysql-data-into-xml-with-php/#findComment-623231 Share on other sites More sharing options...
rilana Posted August 23, 2008 Author Share Posted August 23, 2008 thanks a lot guyes, both of them work. But I understand the first one better.... Barand i wished my brain would work like yours, everytime I feel like I learned someting, I end up realizing I know nothing..... anyway I am trying to figure out the actionsscript now, I have gone thrue so many tutorials and it seems like everybody does it different. And I dont get some things. Does anyone has a good tutorial on how to use xml in flash, my bigest thing I dont understand is if lets say i have 2 news, but I only wanna show about 1 sentens of each news, how do I connect the sentence to the whole news.... ???? Must be with making movieclips somehow... anyway if anyone has a good tutorial for me, I would aprechiate it. Thanks, Rilana Link to comment https://forums.phpfreaks.com/topic/120885-solved-turning-mysql-data-into-xml-with-php/#findComment-623771 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.