Results 1 to 2 of 2

Thread: [solved] Accessing via DB to multiple images fields

  1. #1
    User
    Join Date
    01-29-13.
    Posts
    64

    Default [solved] Accessing via DB to multiple images fields

    Hello to everybody,
    I've been developing an extension in order to print catalog items in PDF with a custom layout. I hooked printArticleAsPdf and wrote the code to get from Database all the information I needed.
    I successfully managed to read single image fields from database and have them printed out in the PDF, using simply

    Code:
    if(!is_null($resultEdizione->immagine) && $resultEdizione->immagine!='a:1:{i:0;N;}')
    {
    	$strArticle = $strArticle.'<td style="width: 47%;">[img]'.$resultEdizione->immagine.'[/img]</td>';
    }
    What I can't get is how to print the first picture of a multiple-images-field. If I check the Multiple selection checkbox in catalog back-end I can upload more than one picture, but what I find in the DB is something quite odd to me. I see

    Code:
    a:1:{i:0;N;}
    if I don't have any picture
    and the following if I have one:

    Code:
    a:2:{i:0;N;i:1;s:41:\"tl_files/catalog_cat_edizioni/piastre.JPG\";}
    This looks somehow like a JSON to me, but how can I get the image URL from there? Please consider that I can't extract the information via regexp (at least I don't think I can) since I could actually have more than one picture saved in that field.

    Thank you in advance
    --
    Marco
    ---------
    Triste e' l'uomo
    che ama le cose
    solo quando si allontanano.
    (Baolian, libro dei pensieri Baol, I, vv. 1240-1242)

  2. #2
    User
    Join Date
    01-29-13.
    Posts
    64

    Default Re: Accessing via DB to multiple images fields

    I'm answering this myself: the content of the multiple-images-fields is a serialized PHP array. Getting the content of the field and unserializing it is enough to get it in array format, and then extracting the image path was plain easy.

    Hope this will be useful to somebody
    cheers
    --
    Marco
    ---------
    Triste e' l'uomo
    che ama le cose
    solo quando si allontanano.
    (Baolian, libro dei pensieri Baol, I, vv. 1240-1242)

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
  •