payney Posted January 8, 2008 Share Posted January 8, 2008 Hi all. I am wanting to query my DB and simply put the results into an XML format. I thought it would be pretty easy but I keep getting problems. Can anyone let me know whats wrong <?php require ('db.php'); if (!($connection = @ mysql_connect($hostname,$username,$password))) die("Could not connect to database"); if (!mysql_select_db($databaseName)) echo "DB ERROR"; $query = mysql_query("select image, caption from image_link"); while ($row = mysql_fetch_array ($query)) { $image = $row['image']; $caption = $row['caption']; $items_output .= <<<EOF <pic> <title>{$image}</title> <caption>{$caption}</caption> </pic> EOF; } ?> <?xml version="1.0" encoding="utf-8" standalone="yes"?> <? echo "<images>".items_output."</images>"; ?> Link to comment https://forums.phpfreaks.com/topic/85006-php-query-results-into-xml/ Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 what is the error? Link to comment https://forums.phpfreaks.com/topic/85006-php-query-results-into-xml/#findComment-433482 Share on other sites More sharing options...
payney Posted January 8, 2008 Author Share Posted January 8, 2008 unexpected T_SL line 15 Link to comment https://forums.phpfreaks.com/topic/85006-php-query-results-into-xml/#findComment-433496 Share on other sites More sharing options...
Ken2k7 Posted January 8, 2008 Share Posted January 8, 2008 Where's line 15? Also you don't need the {} around $image and $caption. Link to comment https://forums.phpfreaks.com/topic/85006-php-query-results-into-xml/#findComment-433497 Share on other sites More sharing options...
priti Posted January 8, 2008 Share Posted January 8, 2008 hi, i tired this and it worked for me. Simple you have remove the extra space form <<<EOF there where 5 extra space delete thema dn refresh it should work smooth. <?php $imgarray=array('image1'=>'caption1', 'image2'=>'captio2', 'image3'=>'caption3'); $items_output=''; foreach($imgarray as $k=>$v) { $image = $k; $caption = $v; $items_output .= <<<EOF <pic> <title>$image</title> <caption>$caption</caption> </pic> EOF; } ?> <?xml version="1.0" encoding="utf-8" standalone="yes"?> <?php echo "<images>".$items_output."</images>"; ?> Regards Link to comment https://forums.phpfreaks.com/topic/85006-php-query-results-into-xml/#findComment-433510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.