在表中并排显示图像

时间:2017-10-18 19:21:27

标签: php html mysql while-loop

我试图在桌面单元格中并排显示5张图像(50x50),但不是并排显示图像,而是每张图像都会显示在一个单独的行中...我该如何解决?

$i = 0;

while ($row = $result->fetch_object()) {

echo "<tr>";

if ($last_entry != $row->project) {

    echo "<td align='center'><textarea name ='project' rows='16' cols='30' style='resize: none'>".$row->project."</textarea></td>";
    echo "<td align='center'>".$row->uid."</td>";
    echo "<td align='center'>".$row->parent_cat."</td>";
    echo "<td align='center'><textarea name ='project_desc' rows='16' cols='30' style='resize: none'>".$row->project_desc."</textarea></td>";
    echo "<td align='center'><textarea name ='desc' rows='16' cols='30' style='resize: none'>".$row->desc."</textarea></td>";
    echo "<td align='center'>".$row->copyright."</td>";
    echo "<td align='center'>Buttons</td>";
echo "</tr>";
echo "<tr>"; 
    $last_entry = $row->project;


}

    //echo "<td align='center' colspan='6'><img src=".$row->url."<border='0'></td>";    
    //echo "<td align='center' colspan='7'>";
    echo "<td colspan='7'><a href='".$row->url."' data-lightbox='".$row->file_name."' data-title='".$row->file_name."'><img src='".$row->url."' border='0' width='50' height='50'></a></td>";

    if ($i%5==0) {

        echo "</tr><tr>";

    }

    $i++;

    if (!$i%5 == 0) {

        echo "<td colspan='7'>&nbsp</td>";
    }

}
//echo "</td>";
//echo "</tr>";


echo "</table>";

这一个几乎正常工作,但在显示第一张图片后,将会中断,然后所有图片将并排展示......

while ($row = $result->fetch_object()) {

if ($last_entry != $row->project) {

    echo "<div class='box-white'>";
        echo "<div class='divTable'>";
            echo "<div class='divTableBody'>";
                echo "<div class='divTableRow'>";
                    echo "<div class='divTableCell'>Projektnamen</div>";
                    echo "<div class='divTableCell'>UID</div>";
                    echo "<div class='divTableCell'>Kategorie</div>";
                    echo "<div class='divTableCell'>Projektbeschreibung</div>";
                    echo "<div class='divTableCell'>Beschreibung</div>";
                    echo "<div class='divTableCell'>Copyright</div>";
                    echo "<div class='divTableCell'>Tools</div>";
                echo "</div>";
            echo "</div>";
        echo "</div>";


            echo "<div class='divTableBody'>";
                echo "<div class='divTableRow'>";
                    echo "<div class='divTableCell'><textarea name ='project' rows='16' cols='30' style='resize: none'>".$row->project."</textarea></div";
                    echo "<div class='divTableCell'>".$row->uid."</div>";
                    echo "<div class='divTableCell'>".$row->parent_cat."   </div>";
                    echo "<div class='divTableCell'><textarea name ='project_desc' rows='16' cols='30' style='resize: none'>".$row->project_desc."</textarea></div>";
                    echo "<div class='divTableCell'><textarea name ='beschreibung' rows='16' cols='30' style='resize: none'>".$row->beschreibung."</textarea></div>";
                    echo "<div class='divTableCell'>".$row->copyright."</div>";
                    echo "<div class='divTableCell'>Buttons</div>";

                echo "</div>";
            echo "</div>";




    $last_entry = $row->project;



}


     echo "<div class='divTableCell'><div style='float:left'><a href='".$row->url."' data-lightbox='".$row->file_name."' data-title='".$row->file_name."'><div class='center-cropped'><img src='".$row->url."' border='0'</a></div></div></div>";

    echo "</div>";

}   

感谢您的支持和建议!

亲切的问候,

的Stefan

1 个答案:

答案 0 :(得分:0)

这是在桌子上(并排)渲染5张图像的一种非常基本的方式,也许它可以帮助您解决问题:

    <!DOCTYPE html>
<html>
<body>
<?php
$pics = array('pic1.jpg', 'pic2.jpg', 'pic3.jpg', 'pic4.jpg', 'pic5.jpg');

echo "<table style='border: 1px solid blue'>";
echo '<tr>';
for ($i=0; $i<5; $i++)
{
$html = <<<HEREDOC_DELIM
<td style='border: 1px solid red'>
<img src="{$pics[$i]}" alt="sometext" width="50" height="50">
</td>
HEREDOC_DELIM;
echo $html;
}
echo '</tr>';
echo '</table>';
?>
</body>
</html>