rilana Posted October 27, 2008 Share Posted October 27, 2008 Hi guyes I am having troubles formatting my dates the right way. I know it's supposed to be easy, but I dont get what I do wrong. <?php $link = mysql_connect("localhost","_","_"); mysql_select_db("_"); $query = 'SELECT * FROM news'; $results = mysql_query($query); $line = 2; echo "<?xml version=\"1.0\"?>\n"; echo "<news>\n"; echo "<n>" . $line. "</n>\n"; while($line = mysql_fetch_assoc($results)) { $datum = date("d-m-Y"); echo "<event>\n"; echo "<title>" . $line["titel"] . "</title>\n"; echo "<date>" . $line["datum"] . "</date>\n"; echo "<text>" . $line["text"] . "</text>\n"; echo "<url>" . $line["link"] . "</url>\n"; echo "</event>\n"; } echo "</news>\n"; mysql_close($link); ?> Can anyone tell me please what I'am doing wrong? Thanks a lot, Rilana Link to comment https://forums.phpfreaks.com/topic/130315-formating-date-in-a-php-xml-file/ Share on other sites More sharing options...
IndyTechNerd Posted October 27, 2008 Share Posted October 27, 2008 Hi guyes I am having troubles formatting my dates the right way. I know it's supposed to be easy, but I dont get what I do wrong. <?php $link = mysql_connect("localhost","_","_"); mysql_select_db("_"); $query = 'SELECT * FROM news'; $results = mysql_query($query); $line = 2; echo "<?xml version=\"1.0\"?>\n"; echo "<news>\n"; echo "<n>" . $line. "</n>\n"; while($line = mysql_fetch_assoc($results)) { $datum = date("d-m-Y"); echo "<event>\n"; echo "<title>" . $line["titel"] . "</title>\n"; echo "<date>" . $line["datum"] . "</date>\n"; echo "<text>" . $line["text"] . "</text>\n"; echo "<url>" . $line["link"] . "</url>\n"; echo "</event>\n"; } echo "</news>\n"; mysql_close($link); ?> Can anyone tell me please what I'am doing wrong? Thanks a lot, Rilana what does your output look like? $datum = date("d-m-Y") would be 27-10-2008 but you've never formatted $line['datum'] (assuming that's a date also). Link to comment https://forums.phpfreaks.com/topic/130315-formating-date-in-a-php-xml-file/#findComment-675879 Share on other sites More sharing options...
rilana Posted October 27, 2008 Author Share Posted October 27, 2008 hy, my output looks like 2008-10-10 unstead of 10-10-2008. I thaught I was formating the echo "<date>" . $line["datum"] . "</date>\n"; by saying that datum is supposed to be formated lke that... $datum = date("d-m-Y"); What do I have to do to formate the $line['datum'] ? sorry I am a bit of a dummy.... Link to comment https://forums.phpfreaks.com/topic/130315-formating-date-in-a-php-xml-file/#findComment-675886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.