0

製品の詳細と画像が2つの異なるテーブルに保存されているWebサイトを構築しています。テーブルを結合したくないので、詳細を取得する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;

誰かが正しい画像のURLを連結する方法を教えてもらえますか?

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 に答える