0

I have an html row which display multiple images. Sometimes, number of images exceeds the screen width. So I want to display the images in the next row if the $columnNumber is a division of 3 ($columnNumber%3==0).

I have the following code to display images:

 $AllCommentImages = explode(",", $jsonArray[$jsonIndex]['Comment_Image']);
 $html.='<tr><td><b>Photos:</b></td></tr>';
 $columnNumber=0;
 $html.='<tr>';
 foreach($AllCommentImages  as $cimg) 
 {
    $commentmysock = getimagesize($cimg);
    $html.='<td><img style="border:15px solid white;border-radius:15px;" src="'.$cimg.'"'.$this->imageResize($commentmysock[0],$commentmysock[1], 200).'/></td>';
    $columnNumber++;                   
 }   
 $html.= '</tr>';

getimagesize is used to reduce the size of the images, the images all are in thumbnail size. I have used this code for pdf generation. I am not sure where to use $columnNumber%3==0 to get 3 images in a row.

4
  • Use bootsrap grid system <div class="col-4"> If you want to make this with table answer commend but you can write less code with bootsrap Commented Jul 18, 2019 at 0:26
  • I am using the above code to display table in a pdf(tcpdf). Restricted html access in tcpdf. So can't use bootstrap for this Commented Jul 18, 2019 at 0:29
  • is border-radius working ? Commented Jul 18, 2019 at 0:31
  • no border radius is not supported Commented Jul 18, 2019 at 0:33

1 Answer 1

1

should work like this

$AllCommentImages = explode(",", $jsonArray[$jsonIndex]['Comment_Image']);
$html.='<tr><td><b>Photos:</b></td></tr>';
$columnNumber=0;

foreach($AllCommentImages  as $cimg) 
{
    if($columnNumber%3==0) $html.='<tr>';
    $commentmysock = getimagesize($cimg);
    $html.='<td><img style="border:15px solid white;border-radius:15px;" src="'.$cimg.'"'.$this->imageResize($commentmysock[0],$commentmysock[1], 200).'/></td>';
    $columnNumber++;
    if($columnNumber%3==0) $html.='</tr>';
}   

while($columnNumber%3!=0){
    $html.='<td></td>';
    $columnNumber++;
}

$html.= '</tr>';
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the help, but the page shows errors if the columnNumber is not a division of 3. Error is Undefined index: rows

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.