hira19 Posted May 8, 2011 Share Posted May 8, 2011 hello everyone, I need to retrieve images and their information from MySQL database in xml format. I have written the following code: <?php $link = mysql_connect("localhost","root",""); // Query the database and get all the records from the All table mysql_select_db("dresses"); $query_rsAll = "SELECT * FROM pictures"; $rsAll = mysql_query($query_rsAll) or die(mysql_error()); $row_rsAll = mysql_fetch_assoc($rsAll); $totalRows_rsAll = mysql_num_rows($rsAll); ?><?php echo('<?xml version="1.0" encoding="utf-8"?>');?> <dresses> <?php if ($totalRows_rsAll > 0) { // Show if recordset not empty ?> <?php do { ?> <pictures> <?php print('<image>' . ($row_rsAll['image']) . '</image>'); ?> <br> <?php print('<ext>' . $row_rsAll['ext'] . '</ext>'); ?> <br> <?php print('<category>' . $row_rsAll['category'] . '</category>'); ?> <br> <?php print('<price>' . $row_rsAll['price'] . '</price>'); ?> <br> <?php print('<buy>' . $row_rsAll['buy'] . '</buy>'); ?> </pictures> <?php } while ($row_rsAll = mysql_fetch_assoc($rsAll)); ?> <?php } // Show if recordset not empty ?> </dresses> <?php mysql_free_result($rsAll); ?> Output: /9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAUAAA/+4ADkFkb2JlAGTAAAAAAf/bAEMAAgICAgICAgICAgMCAgIDBAMCAgMEBQQEBAQEBQYFBQUFBQUGBgc/NFvKzPC1vfXce5Ld8oVdBumQHd5eCKAPxr/AGhf2n/iL8etUjl1CHTtC0zSJVutE0nSrSLzrdlBzKNTaL7cSy8NhlRv7g6UAfOfhi1vr6+N3qV2yWmkxxT2tnHkCaWSQpGi5KkABXbGOwGM0Af1a/DvZJOKAP5vv2qb221X4meKtRuZraK98Q6jJq8WjQXKSm0S/meaO2vE3sqXCLtLIGOW3EY+SgDzLw5pM9tpUUsem208+ptI8iG0AbywTguXJdsrzz8uMYoA244p7eeS4R7W2WQbEawthEzqv3S8qElto4AxkCgDC8Q21nfaZLcXMbiQxxSyQ3MaeYCsnU7l3/xAnJ4oAzYLPXNetntbe6h0LSI38vHlvJd3I7iPIKqOOTmgBbvwpokVsEjErOTgAgnOeaANy5dLASc+vnc0AfTlABQAUAFABQAUAFABQAUAFABQAUAFABQAUAFAH/9k= png kurta collection 2000 http://localhost/Picturz.php Issue: The problem is that instead of displaying images in proper format it is showing them in character form. Can anyone help me solve this issue? Quote Link to comment https://forums.phpfreaks.com/topic/235831-php-xml-help/ Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 So you're storing the images as binary data in your database? For one, XML doesn't support the image tag, as far as I know. You best bet will be to link it to a script (using the image's unique ID in the database) that will send the browser image headers, and dump out the raw binary data of the picture. There are lots of tutorials on how to do this. Here's one http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/3/ He doesn't sanitize user input in that example though. I suggest doing it to avoid SQL injection Quote Link to comment https://forums.phpfreaks.com/topic/235831-php-xml-help/#findComment-1212260 Share on other sites More sharing options...
hira19 Posted May 8, 2011 Author Share Posted May 8, 2011 yea i am using BLOB for storing images.. and i am not using image tag in xml for display purpose but is just for identification purpose. i just want to know how to retrieve images from database and display them using xml. Quote Link to comment https://forums.phpfreaks.com/topic/235831-php-xml-help/#findComment-1212261 Share on other sites More sharing options...
xyph Posted May 8, 2011 Share Posted May 8, 2011 XML isn't meant to display images. What you want to do is have the row's ID in the XML file, then use a script like the one in my example to turn that ID into an image for use in a browser. Quote Link to comment https://forums.phpfreaks.com/topic/235831-php-xml-help/#findComment-1212270 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.