0

I have a problem with XML data generated by a PHP file.

here is my code:

$requestXmlBody .= "<PictureURL>";

    //find black

  while($row = mysql_fetch_object($ergebnis))
  {
    $posblack = strpos($row->image, $findBLACK);
    if ($posblack !== false) 
    {
    echo $row->image;
    }
  }
    $requestXmlBody .= "</PictureURL>";

This code will generate the XML Code

<PictureURL></PictureURL>

but not the name I fetch from the database. The database query is working but my problem ist to have it inserted between the XML code. Usually a variable is inserted like this

$requestXmlBody .= '<PictureURL>$variable</PictureURL>';

I just don't know how to wrap this around my database query.

Any help is very appreciated.

2
  • Double check that you are getting rows returned by assigning $rows outside of your while loop and echoing the count. Commented Mar 7, 2013 at 19:17
  • 1
    You are mixing string concatenation (for the xml tags) with a raw echo (for the image URL). Decide on one. Place both in the loop and if block. Commented Mar 7, 2013 at 19:18

2 Answers 2

1

Something like this?

while($row = mysql_fetch_object($ergebnis)) {
  $posblack = strpos($row->image, $findBLACK);
  if ($posblack !== false) {
    $requestXmlBody .= "<PictureURL>";
    $requestXmlBody .= $row->image;
    $requestXmlBody .= "</PictureURL>";
  }
}
Sign up to request clarification or add additional context in comments.

1 Comment

It worked with the '$requestXmlBody .= "<PictureURL>";' outside the loop. Thanks a lot. this made my day :)
0

You are echo'ing $row->image instead of appending to $requestXmlBody

Change your code to:

$requestXmlBody .= $row->image;

2 Comments

Are you ever going to have more than one result? If so, you should have the <PictureURL> part added to the while loop.
It's only one result. Thanks anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.