简体   繁体   English

从数据库(joomla)中按ID获取简介图片

[英]Get intro image by ID from database (joomla)

I am trying to read the intro image from a joomla database. 我正在尝试从joomla数据库读取简介图片。 I have a list of products, that each need to show the intro image that matches the ID of the product. 我有一个产品列表,每个产品都需要显示与产品ID匹配的介绍图片。

//  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: 然后在foreach中,我输入以下代码:

<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. 我读了一些有关json_decode的信息,以从数据库字段获取图像路径。

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":""}

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. //编辑您的信息以修复图片标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM