Possible to sort contents of a table's field?

Hi everyone,

I’m returning a number of image galleries from my table.

Each field contains code in the following format:

Row one might have a field with:

<img src=“images/wine/1.jpg” alt=“” />
<img src=“images/wine/2.jpg” alt=“” />

Row two might have a field with:

<img src=“images/beer/1.jpg” alt=“” />
<img src=“images/beer/2.jpg” alt=“” />

Instead of having the full image source code in each field, is it possible to just have the image numbers in the field like so:

1, 2, 3, 4, 5

I have already defined the path to where the images are located - $row[‘folder’]. Now I just want to loop out the numbers in the image column.

<?php print’<img src=“‘.$row[‘folder’].’‘.$row[‘image’].’.jpg” alt=“” />';?>

Don’t know if this is possible…

Thank you for your help!

it will be better if you use background image and number in text
create background class with image

Hi,

thanks, but I’m not sure what you mean.

Do you think it would be possible to add the contents of the field (1, 2, 3, 4, 5) to an array and then loop out the numbers? Maybe use the explode function?

I’m trying to determine whether or not the contents of a field can be manipulated.

I wouldn’t save the full path. Just the image name. And yes you can put this into a string separated by “,” or “|” which you can then explode.
1.jpg|2.jpg|3.jpg|4.jpg|5.jpg

So say you have some images and are going to add another. You can build an array for current images by querying record and explode that field.
Add the new image to this array, then implode the array to build the string again and update your table.

Hi Drummin,

thank you for your help. I got the following the following code to work:



<?php

$w = explode("-", $row['images']);
foreach ($w as $g ) {
echo '<img src="'.$row['folder'].''.$g.'.jpg" alt="" />';
}

?>