0

我正在建立一个网站,其中包含存储在 2 个不同表中的产品详细信息和图像。我不想加入表格,所以我有 2 个查询来获取详细信息。

我所做的是通过product id抓取所有图像。问题是,我想存储所有图像 url, $img_block这样我就可以显示产品详细信息和所有图像,除了第一个产品。所有其他产品都包含产品的先前图像。

product 1 : image p1-1 and image p1-2
product 2 : image p1-1 image p1-2 image p2-1
product 3 : image p1-1 image p1-2 image p2-1 image 3-1

我的代码:

foreach ($products as $key=>$product):

$images = $this->control_model->product_images($product['pid']);

            foreach ($images as $image):

            $img_block .='<img src="'.$image['url'].'" height="75px" width="75px">' ;

            endforeach;

$msg .= '<div class="one_half_full">
            <div class="listbox">
            <div class="list_text">

            <h4 style="font-weight:bold"><a href="#">'.$product['title'].'</a></h4>
            <p>
              <div class="clearfix" id="images"> 
               '.$img_block.'
              </div>';

endforeach;

有人可以让我知道如何连接正确的图片网址吗?

4

1 回答 1

1

只需初始化之$img_block类的:(我添加最后的报价......)

foreach ($products as $key=>$product):

$images = $this->control_model->product_images($product['pid']);
$img_block = '';
            foreach ($images as $image):

            $img_block .='<img src="'.$image['url'].'" height="75px" width="75px">' ;

            endforeach;

$msg .= '<div class="one_half_full">
            <div class="listbox">
            <div class="list_text">

            <h4 style="font-weight:bold"><a href="#">'.$product['title'].'</a></h4>
            <p>
              <div class="clearfix" id="images"> 
               '.$img_block.'
              </div>';

endforeach;
于 2013-03-26T13:51:14.600 回答