I am trying to read the intro image from a joomla database. I have a list of products, that each need to show the intro image that matches the ID of the product.
// content $content = "SELECT * FROM `snm_content` WHERE catid = 13"; $contentcon = $conn->query($content); $contentcr = array(); while ($contentcr[] = $contentcon->fetch_array()); $img = $contentcr[0]['images']; $plaatje = explode('/', $img); $plaatje = explode('"', $plaatje[2]); $plaatje = $plaatje[0]; $img = preg_replace('/[^a-zA-Z0-9']/', '_', $img); $img = explode('___', $img); $img = $img[1];
Then in a foreach I put the following code:
<img src="cms/images/website/'.$plaatje.'" alt="" class="company_logo">
This shows the same image for every product though.
I read something about json_decode to get the image path from the database field.
How can I get the correct image for every product?
The following code prints the correct array:
print_r($content['images']);
Example of a field in the database with all the possible images (intro, full etc)
{"image_intro":"images/website/Airco_blog.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
Advertisement
Answer
I guess this will work for you :
$article_images = $content['images'] // Get image parameters of the article $pictures = json_decode($article_images); // Split the parameters apart echo "<img src='" . $pictures->{'image_intro'} . "' alt='" . $pictures->{'image_intro_alt'} . "'>"; // get the intro image
// Edited your post to fix the image tag.