Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP创建动态表_Php_Dynamic_Html Table_Dynamic Data_Dynamic Tables - Fatal编程技术网

用PHP创建动态表

用PHP创建动态表,php,dynamic,html-table,dynamic-data,dynamic-tables,Php,Dynamic,Html Table,Dynamic Data,Dynamic Tables,我正在尝试用PHP创建一个动态表。我有一个显示数据库中所有图片的页面。 我需要的表只有5列。如果返回的图片超过5张,则应创建一个新行,并继续显示其余图片 有人能帮忙吗 代码如下: 主页中的代码:- <table> <?php $all_pics_rs=get_all_pics(); while($pic_info=mysql_fetch_array($all_pics_rs)){ echo "<td>&

我正在尝试用PHP创建一个动态表。我有一个显示数据库中所有图片的页面。 我需要的表只有5列。如果返回的图片超过5张,则应创建一个新行,并继续显示其余图片

有人能帮忙吗

代码如下: 主页中的代码:-

    <table>
    <?php
        $all_pics_rs=get_all_pics();
        while($pic_info=mysql_fetch_array($all_pics_rs)){
        echo "<td><img src='".$pic_info['picture']."' height='300px' width='400px' /></td>";
            } 
?>
</table>
此代码正在创建一行。我想不出如何才能得到多行

$max\u/行=5;
$max_per_row = 5;
$item_count = 0;

echo "<table>";
echo "<tr>";
foreach ($images as $image)
{
    if ($item_count == $max_per_row)
    {
        echo "</tr><tr>";
        $item_count = 0;
    }
    echo "<td><img src='" . $image . "' /></td>";
    $item_count++;
}
echo "</tr>";
echo "</table>";
$item_count=0; 回声“; 回声“; foreach($images作为$image) { 如果($item\u count==$max\u/行) { 回声“; $item_count=0; } 回声“; $item_count++; } 回声“; 回声“;
$maxcols=5;
$i=0;
//打开表及其第一行
回声“;
回声“;
而($image=mysql\u fetch\u assoc($images\u rs)){
如果($i==$maxcols){
$i=0;
回声“;
}
回声“;
$i++;
}
//添加空的以平衡行中的单元格数量:

虽然($i仅供参考-您被否决,因为您没有发布任何代码。如果您可以编辑此问题以提供您尝试过的相关代码示例,请将其标记以供版主注意以供审阅。若要编辑,只需单击问题下的“编辑”链接。若要标记此问题,请单击“标记”链接,选择“其他”,并让我们知道它已准备就绪被检阅。@Tim Post:我真的不同意你的行动。我认为他的问题非常清楚。我在这块板上看到过比这更糟糕的问题。@Jules我对此持怀疑态度(旗帜是准确的),我现在就打开。@Tim Post:好吧,我会这样做的……我是新来的……我不知道发布代码是绝对必要的。您已经在for之外定义了
I
,所以只需使用它在结束
之间填充
for(;$I<5/*幻数!糟糕!*/;+$I{{echo”“;}
echo”“;
。不需要除法或其他任何东西。@RedX:是的,你说得对。这是一种更简单的方法。将相应地编辑我的答案。
$max_per_row = 5;
$item_count = 0;

echo "<table>";
echo "<tr>";
foreach ($images as $image)
{
    if ($item_count == $max_per_row)
    {
        echo "</tr><tr>";
        $item_count = 0;
    }
    echo "<td><img src='" . $image . "' /></td>";
    $item_count++;
}
echo "</tr>";
echo "</table>";
$maxcols = 5;
$i = 0;

//Open the table and its first row
echo "<table>";
echo "<tr>";
while ($image = mysql_fetch_assoc($images_rs)) {

    if ($i == $maxcols) {
        $i = 0;
        echo "</tr><tr>";
    }

    echo "<td><img src=\"" . $image['src'] . "\" /></td>";

    $i++;

}

//Add empty <td>'s to even up the amount of cells in a row:
while ($i <= $maxcols) {
    echo "<td>&nbsp;</td>";
    $i++;
}

//Close the table row and the table
echo "</tr>";
echo "</table>";
<table>
    <tr>
        <td><img src="image1.jpg" /></td>
        <td><img src="image1.jpg" /></td>
        <td><img src="image1.jpg" /></td>
        <td><img src="image1.jpg" /></td>
        <td><img src="image1.jpg" /></td>
    </tr>
    <tr>
        <td><img src="image1.jpg" /></td>
        <td><img src="image1.jpg" /></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;<td>
    </tr>
</table>