Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.