SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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!

  2. #2
    SitePoint Enthusiast
    Join Date
    Jan 2013
    Posts
    26
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it will be better if you use background image and number in text
    create background class with image

  3. #3
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    SitePoint Guru bronze trophy
    Join Date
    Feb 2013
    Posts
    730
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    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.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    361
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Drummin,

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

    PHP Code:

    <?php

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

    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •