sullyman Posted September 17, 2008 Share Posted September 17, 2008 Hi folks, i need some help extracting a single mysql column [images] containing images (image01.jpg, image02.jpg, image03.jpg) to form an xml page. I have got the following to work $image = "http://www.site.ie/files/".cleanText($row["images"]); but the result is <image>http://www.site.ie/files/image01.jpg image02.jpg image03.jpg)</image> I would like it to come out as <image>http://www.site.ie/files/image01.jpg, http://www.site.ie/files/image02.jpg, http://www.site.ie/files/image03.jpg</image> If there is no image for that row, i would like the xml to show nothing e.g. <image></image> Is the above possible. Can anyone help please? Thanks, Sully Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/ Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 You shouldn't store CSVs in a single database column in the first place. Fix that and then this becomes much easier. Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644147 Share on other sites More sharing options...
sullyman Posted September 17, 2008 Author Share Posted September 17, 2008 How do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644148 Share on other sites More sharing options...
sullyman Posted September 17, 2008 Author Share Posted September 17, 2008 i should have said i need some help extracting a single row from mysql where the values are stored in the column [images] containing the following image files (image01.jpg, image02.jpg, image03.jpg) to form an xml page. Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644150 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 Yes, but you should never store values separated by a comma inside of a single database column. You need to use an intermediary table to break it down. Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644158 Share on other sites More sharing options...
sullyman Posted September 17, 2008 Author Share Posted September 17, 2008 Thanks for reply. In the database they have no commas. They are stored as image01.jpg image02.jpg image03.jpg etc. I would like them to have a comma or a | symbol to seperate them in the XML file Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644164 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 That's not the point. You shouldn't have more than one value in a single column. Commas, spaces, pipes (|), anything...doesn't matter. There should be another table so you can do a simple JOIN query and then use implode(). You shouldn't have to parse MySQL results. Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644167 Share on other sites More sharing options...
sullyman Posted September 17, 2008 Author Share Posted September 17, 2008 I understand now. Unfortunately it is a CMS package that i purchased. This is the way it stores the images associated with each record Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644168 Share on other sites More sharing options...
DarkWater Posted September 17, 2008 Share Posted September 17, 2008 Lol, you purchased something that does that? =P Kinda funny. You should go complain to the creator that his code is bad. Really bad. If you *REALLY* aren't able to change it, I guess you could do: <?php //assume you're connected $query = "SELECT images FROM your_table WHERE id=$id"; //who cares, change this how you need to =P $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_assoc($result); $row = str_replace(' ', ',', $row); //continue from here ?> Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644174 Share on other sites More sharing options...
sullyman Posted September 17, 2008 Author Share Posted September 17, 2008 I'm a noob so be gentle I will have to test below and get back to you as it will probably take me a day to figure out what you've wrote Quote Link to comment https://forums.phpfreaks.com/topic/124711-strip-php-for-xml/#findComment-644183 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.