Show images in php table

images php coding issues or problems here.

Moderators: macek, egami, gesf

jeffers2014
New php-forum User
New php-forum User
Posts: 1
Joined: Mon Apr 14, 2014 1:35 am

Show images in php table

Postby jeffers2014 » Mon Apr 14, 2014 1:52 am

Im trying to display 5 by 3 table from an array.

My table

Code: Select all

 W1 |  W1 | W1

Code: Select all

 W2 |  W2 | W2

Code: Select all

 W3 |  W3 | W3

Code: Select all

 W4 |  W4 | W4

Code: Select all

 W5 |  W5 | W5

Code: Select all

<?PHP

$ds ='\image';
$imagefile = array("EX_W1_01.png", "EX_W1_02.png", "EX_W2_01.png","EX_W3_01.png");
echo "<pre>"; print_r($imagefile);
$file = 'blank.png';
$d = $ds.$file;

echo "<table border = 1 width=\"540px\" cellspacing=\"0px\" cellpadding=\"0px\">";
for($row=1;$row<=5;$row++){
   echo "<tr>";

      for($col=1;$col<=3;$col++){

           // echo"<td height=60px>W$row</td>";
           //if()
           echo"<td height=60px>W$row<img border = 1 height = 120 width = 120 src = $d ></td>" .PHP_EOL;

      }
   echo "</tr>";

}
echo "</table>";     
?>


my desire table output is to display the images dependent on the middle of the file name array. eg W1,W2, if Wx is not in array the cell will be display with blank.png

Code: Select all

 EX_W1_01.png | EX_W1_02.png | blank.png | 
 EX_W2_01.png | Blank.png  | blank.png | 
 EX_W3_01.png | Blank.png  | Blank.png | 
 Blank.png        | Blank.png   | blank.png |
 Blank.png        | Blank.png   | blank.png |


Thank you very much

seandisanti
php-forum Fan User
php-forum Fan User
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm

Re: Show images in php table

Postby seandisanti » Mon Apr 14, 2014 8:22 am

Like with any other programming situation there are a few ways to accomplish this. I think the right way would be with css, you can set a min-width for each column and that would take care of it. You could also use a ternary expression like:

Code: Select all

echo empty($array[$column][$row])?'no picture':'picture';
 

except replace those strings with strings to display what you want of course


Return to “PHP coding => Images”

Who is online

Users browsing this forum: No registered users and 1 guest