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>"; ?> Quote 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? Quote 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 Quote 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. Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.