douzao2590 2015-12-02 10:53
浏览 55
已采纳

从数据库(joomla)获取ID的介绍图像

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":""}
  • 写回答

1条回答 默认 最新

  • douzhou7124 2015-12-03 05:05
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog