Print Image Array in PHP Horizontally

0

I have the following code whose function is to load an array with a piece of html code that prints an image. Such a code does its job, however when displayed on the screen, the images are printed one below the other as shown below. I need to show them horizontally, for aesthetic and usability purposes.

the code below.

<div id="selector">
        <?php

            $j = "<table>   
                <tr>
                    <td>
                        <a href='agregar_cliente.html' class='fancybox fancybox.iframe'><img src='imgs/blue.png'></a>
                        <p>Habitación </p>
                    </td>           
                </tr>
            </table>";


                $array[10] = 1;

                for($i=0;$i<5;$i++){
                    $array[$i]= $j; 
                }

                for($i=0;$i<5;$i++){
                    echo "$array[$i]";
                }           
        ?>
</div>

What should I do to show it horizontally?

    
asked by Jesus Gregorio Altuve Roa 14.02.2018 в 01:45
source

1 answer

0

The tag tr is a table row so everything inside each one of them will occupy a single line. Separate these by declaring a table in each element of the array. To correct it you must use table and tr only once, inside the tr you can place the td with the images.

For illustration:

The output of the current code is:

    <tr><td>Imagen</td></tr>
    <tr><td>Imagen</td></tr>
    ....
    <tr><td>Imagen</td></tr>

The desired output is:

    <tr>
     <td>Imagen</td>
      <td>Imagen</td>
      ....
      <td>Imagen</td>

    </tr>

Try this code:

<?php

            $j = "
                    <td>
                        <a href='agregar_cliente.html' class='fancybox fancybox.iframe'><img src='imgs/blue.png'></a>
                        <p>Habitación </p>
                    </td>           

           ";


                $array[10] = 1;

                for($i=0;$i<5;$i++){
                    $array[$i]= $j; 
                }
                 echo "<table><tr>"
                for($i=0;$i<5;$i++){
                    echo "$array[$i]";
                }           
                echo"</tr></table>"
        ?>
    
answered by 14.02.2018 / 02:06
source