Jump to content

PHP query results into XML


payney

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.