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.

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

报告相同问题?

悬赏问题

  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录