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 ATAC测序到底用什么peak文件做Diffbind差异分析
  • ¥15 安装ubantu过程中第一个vfat 文件挂载失败
  • ¥20 GZ::CTF如何兼容一些靶机?
  • ¥15 etcd集群部署问题
  • ¥20 谁可以帮我一下问一下各位
  • ¥15 为何重叠加权后love图的SMD与svyCreateTableOne函数绘制基线表的不一致
  • ¥15 QFILHelper怎么恢复全字库,提示进程已完成,只能恢复分区文件
  • ¥150 求 《小魔指》街机游戏机整合模拟软件
  • ¥20 你好,我想问下easyExcel下拉多选,或者复选框可以实现吗
  • ¥20 双非跨考工科哪个专业和方向就业前景好?