Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.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_Html_Mysql - Fatal编程技术网

Php 将表行拆分为列

Php 将表行拆分为列,php,html,mysql,Php,Html,Mysql,我有一部分代码从Mysql数据库中提取数字,并使用PHP将其显示到HTML表中。然而,我有很多来自这一行的数据,很容易超过100行,我想按25左右的长度分成列 这是迄今为止的代码: while($row = mysql_fetch_array($results)) { echo "<tr>"; echo "<td>" . $Destination = $row["Destination"] . "</td>"; echo "</

我有一部分代码从Mysql数据库中提取数字,并使用PHP将其显示到HTML表中。然而,我有很多来自这一行的数据,很容易超过100行,我想按25左右的长度分成列

这是迄今为止的代码:

 while($row = mysql_fetch_array($results))
{
    echo "<tr>";
    echo "<td>" . $Destination = $row["Destination"] . "</td>";
    echo "</tr>";
}
while($row=mysql\u fetch\u array($results))
{
回声“;
回显“$Destination=$row[“Destination”]”;
回声“;
}
我应该继续使用表还是有更好的方法来保持良好的格式和拆分?这将用于web视图,所以我想继续使用CSS或HTML元素

试试这个:

<?php
$i = 1;
$columns = 25;
while($row = mysql_fetch_array($results))
{
    if($i == 1){ echo '<tr>'; }
    echo "<td>" . $Destination = $row["Destination"] . "</td>";
    $i++;
    if($i == ($columns + 1)) { echo '</tr>'; $i = 1; }
}
?>

试试这个:

<?php
$i = 1;
$columns = 25;
while($row = mysql_fetch_array($results))
{
    if($i == 1){ echo '<tr>'; }
    echo "<td>" . $Destination = $row["Destination"] . "</td>";
    $i++;
    if($i == ($columns + 1)) { echo '</tr>'; $i = 1; }
}
?>

$i=1;
回声“;
while($row=mysql\u fetch\u数组($results))
{
回显“$row['Destination']”;
如果($i%25==0)回显“”;
$i++;
}
回声“;
$i=1;
回声“;
while($row=mysql\u fetch\u数组($results))
{
回显“$row['Destination']”;
如果($i%25==0)回显“”;
$i++;
}
回声“;

使用表格,没问题。。。。了解如何使用PHP的模运算符
%
确定何时抛出新的
使用表,没有问题。。。。了解如何使用PHP的模运算符
%
来确定何时抛出一个新的
好的,由于某种原因在我脑海中过于复杂的。有没有可能让它检测一个页面的长度,或者我需要javascript或css?很好,出于某种原因,这在我的头脑中过于复杂了。是否可以让它检测长度以适应一个页面,或者我需要javascript或css?我更喜欢这个,我相信它有一个更简洁、更干净的方法。谢谢。@SethEarby您可以使用$i%2==0I将css附加到tr或td。我更喜欢这个,我相信它有一个更简洁、更清晰的方法。谢谢。@SethEarby您可以使用$i%2==0将css附加到tr或td