PHP表格格式

PHP表格格式,php,Php,我将下面的代码放在一起,通过下拉菜单进行选择后创建一个表 echo "<table>"; $result=mysql_query($query); while($rows=mysql_fetch_array($result)){ echo "<tr>"; echo "<th>Find Name:</th>"; echo "<th>Find Description:</th>"; echo "</tr>"; ech

我将下面的代码放在一起,通过下拉菜单进行选择后创建一个表

echo "<table>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
echo”“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;
我遇到的问题是,对于返回的每个记录,“头”都是重复的。可以找到live页面。我只是想知道是否有人可以看看这个,告诉我哪里出了问题


我为这个简单的问题道歉,但我已经看了一段时间了,我就是找不到答案。我认为它只需要一双新的眼睛来观察它。

您的头被重复,因为您正在循环中为查询返回的每一行写入它们。您只需将标题移出循环,以便在查询返回的行开始打印之前,它们只被写入一次:

echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";

$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
  echo "<tr>";
  echo "<td>".$rows['findname']."</td>";
  echo "<td>".$rows['finddescription']."</td>";
  echo "</tr>";
}
echo "</table>";
echo”“;
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;

试试这个,您只需要将标题从while循环中取出即可

echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";

$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){

echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
echo”“;
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;

标题重复,因为它们在while循环中,所以应该可以正常工作

echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){

echo "<tr>";
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
echo”“;
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;

答案很明显,您正在重复循环中标题的输出。移动

while($rows=mysql_fetch_array($result)){
第一次之后

echo "</tr>";
echo”“;
这应该可以:

echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
$result=mysql_query($query);
while($rows=mysql_fetch_array($result)){
    echo "<tr>";
    echo "<td>".$rows['findname']."</td>";
    echo "<td>".$rows['finddescription']."</td>";
    echo "</tr>";
    }
echo "</table>";
echo”“;
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;
更改为:

echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";
echo "<tr>";
while($rows=mysql_fetch_array($result)){
echo "<td>".$rows['findname']."</td>";
echo "<td>".$rows['finddescription']."</td>";
echo "</tr>";
}
echo "</table>";
echo”“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
回声“;
while($rows=mysql\u fetch\u array($result)){
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;

您需要将标题放在while循环之外:

echo "<table>";
echo "<tr>";
echo "<th>Find Name:</th>";
echo "<th>Find Description:</th>";
echo "</tr>";

$result = mysql_query($query);

while ($rows = mysql_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $rows['findname'] . "</td>";
    echo "<td>" . $rows['finddescription'] . "</td>";
    echo "</tr>";
}

echo "</table>";
echo”“;
回声“;
echo“查找名称:”;
回声“查找描述:”;
回声“;
$result=mysql\u query($query);
while($rows=mysql\u fetch\u array($result)){
回声“;
回显“$rows['findname']”;
回显“$rows['finddescription']”;
回声“;
}
回声“;

All,非常感谢您的帮助。亲切的问候。