[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
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
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