2016-08-16 5 views
-1

PHP를 사용하여 갤러리에서 이미지를 가져 왔습니다. 하지만 이제는 한 행에 두 개의 이미지 만 표시하려고합니다. 내가 지정한 $content에 반환하십시오.배열에서 PHP의 한 행에 두 개의 이미지가있는 방법

도와주세요.

function CreateGalleryImages($types) { 

    $galleryArray = array(); 
    $galleryModel = new GalleryModel(); 
    $galleryArray = ($galleryModel -> getGalleryByTypes($types)); 
    $result = ""; 

    foreach ($galleryArray as $gallery) { 
     for ($i = 0; $i < 2; $i++){ 
      $result = "<td>" 
         ."<img runat = 'server' src = 'http://localhost/schoolwb/event/$gallery' height=500 width=500 />" 
         ."</td>"; 
     } 
     $result = "<tr>.$result.</tr>"; 
    } 
    return "<table class = 'GalleryTable'> . $result . </table>"; 
} 

답변

0

당신은 결과를 concatenate하고 $result에 저장해야합니다.

<?php 
function CreateGalleryImages($types){ 
    $galleryArray = array(); 
    $galleryModel = new GalleryModel(); 
    $galleryArray = ($galleryModel->getGalleryByTypes($types)); 
    $result = ""; 

    foreach ($galleryArray as $gallery){ 
    $cl = ""; 
    for ($i = 0;$i<2;$i++){ 
     $cl .= "<td>" 
       ."<img runat = 'server' src = 'http://localhost/schoolwb/event/$gallery' height=500 width=500 />" 
      ."</td>"; 
    } 
    $result .= "<tr>.$cl.</tr>"; 
    } 
    return "<table class = 'GalleryTable'>.$result.</table>"; 
} 
?> 
시도
관련 문제