brooksh Posted June 16, 2009 Share Posted June 16, 2009 I can't seem to figure this out. If I manually input the image source it works, but if I use a query it errors out. In the header I am using: header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; In the content I have <image source="house.jpg" title="Front view" description=""/> But if I use this query instead it doesn't work. I have verified that the query is good. <? $result = mysql_query("SELECT DISTINCT name,caption,description,rank FROM images WHERE id = '$id' ORDER BY rank"); while($row = mysql_fetch_array($result)){ ?> <image source="<?=$row[file_name]?>" title="<?=$row[caption]?>" description="<?=$row[description]?>" /> <? } ?> Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/ Share on other sites More sharing options...
PugJr Posted June 16, 2009 Share Posted June 16, 2009 Don't you have to have the $row[file_name] and the others as $row['file_name']? I remember having that problem awhile ago. Try adding the single quotes. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856863 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 no quotes, single quotes and double quotes doesn't matter. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856866 Share on other sites More sharing options...
PugJr Posted June 16, 2009 Share Posted June 16, 2009 Wait, what exactly isn't working? Get an mysql error or the content just won't show up? Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856867 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 The query works. When I call the xml file and manually input the info, the pictures show up, but if I use a query it doesn't work. When looking at the xml file, they look identical. Manual: <image source="image18.jpg" title="test" description=""/> sql query: <image source="image14.jpg" title="Front view" description=""/> Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856871 Share on other sites More sharing options...
priti Posted June 16, 2009 Share Posted June 16, 2009 are you trying to insert image tag in XML ??? Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856872 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 Yes I am adding an image tag in an php xml file. Named xml.php with specialized headers. It works if I manually input the data, but if I call it through a query it doesn't and I have verified several times that the query works. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856874 Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 The closing xml tag will close your php tags. Change this: echo '<?xml version="1.0" encoding="UTF-8"?>'; to this: ?> <?xml version="1.0" encoding="UTF-8"?> <?php Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856877 Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 I should also mention that the image tag attribute is not 'source', it's 'src'. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856878 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 I'm going to have to disagree with you haku. <?php header("Content-type: text/xml"); echo '<?xml version="1.0" encoding="UTF-8"?>'; ?> This works just fine as a php file. The way this script is used, it is actually called as source, not src. Like I mentioned before, it works fine if I manually input <image source="image18.jpg" title="test" description=""/> Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856881 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 It was supposed to be echo '<?xml version="1.0" encoding="UTF-8"?>'; Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856882 Share on other sites More sharing options...
priti Posted June 16, 2009 Share Posted June 16, 2009 keep <image source="image18.jpg" title="test" description=""/> in CDATA Tag and try Might be your '<' and '>' is getting parsed <![CDATA[<image source="image18.jpg" title="test" description=""/>]]> Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856884 Share on other sites More sharing options...
haku Posted June 16, 2009 Share Posted June 16, 2009 Feel free to not learn from my mistakes all you want. But the mistake I have made in the past was that the closing xml tag closed off my php tag. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856885 Share on other sites More sharing options...
brooksh Posted June 16, 2009 Author Share Posted June 16, 2009 It was worth a shot but <![CDATA]]> didn't work. Haku. How is this closing my xml tag? I did try what you said, but it just gave me errors because I want it to echo <?xml version="1.0" encoding="UTF-8"?> and if I close it off with a single quote I can echo it. I reads just fine if I view source. echo '<?xml version="1.0" encoding="UTF-8"?>'; I have used this exact header in different php xml files. Link to comment https://forums.phpfreaks.com/topic/162338-solved-xml-file-works-if-i-dont-use-a-query/#findComment-856886 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.