gpt4 book ai didi

php - mysql_fetch_array 跳过第一行

转载 作者:太空狗 更新时间:2023-10-29 13:35:11 25 4
gpt4 key购买 nike

我正在使用相同的过程来创建和填充表 - 除了每个表中的第一行被跳过外,一切正常。可以使用另一双眼睛,因为我似乎无法查明问题所在。提前致谢。

   $query = "SELECT * FROM members";
$results = mysql_query($query);
$row = mysql_fetch_array($results);


//echo my <table> start and headings;

while ($row = mysql_fetch_array($results))
{
echo "<tr><td>".$row['Last Name']."</td>";
echo "<td>".$row['First Name']."</td>";
echo "<td>".$row['Middle Name']."</td>";
echo "<td>".$row['Sfx']."</td>";
echo "<td>".$row['Prf']."</td>";
echo "<td>".$row['Spouse/SO']."</td>";
echo "<td>".$row['Ancestor']."</td>";
echo "<td>".$row['Status']."</td>";
echo "<td>".$row['Address 1']."</td>";
echo "<td>".$row['Address 2']."</td>";
echo "<td>".$row['City']."</td>";
echo "<td>".$row['ST']."</td>";
echo "<td>".$row['Zip 5']."</td>";
echo "<td>".$row['Zip 4']."</td>";
echo "<td>".$row['Home Phone']."</td>";
echo '<td><a href="mywebsite/mypage.php?id=' . $row['id'] . '">Bio</a></td></tr>';
}

echo "</table><hr>";

最佳答案

您正在调用 mysql_fetch_array 两次...一次在循环之前,一次在循环时。

如果您需要用于构建标题行的种子行,您最好在此处使用 do..while 循环。

$query = "SELECT * FROM members";
$results = mysql_query($query);
$row = mysql_fetch_assoc($results);

//echo my <table> start and headings;

do
{
echo "<tr><td>".$row['Last Name']."</td>";
echo "<td>".$row['First Name']."</td>";
echo "<td>".$row['Middle Name']."</td>";
echo "<td>".$row['Sfx']."</td>";
echo "<td>".$row['Prf']."</td>";
echo "<td>".$row['Spouse/SO']."</td>";
echo "<td>".$row['Ancestor']."</td>";
echo "<td>".$row['Status']."</td>";
echo "<td>".$row['Address 1']."</td>";
echo "<td>".$row['Address 2']."</td>";
echo "<td>".$row['City']."</td>";
echo "<td>".$row['ST']."</td>";
echo "<td>".$row['Zip 5']."</td>";
echo "<td>".$row['Zip 4']."</td>";
echo "<td>".$row['Home Phone']."</td>";
echo '<td><a href="mywebsite/mypage.php?id=' . $row['id'] . '">Bio</a></td></tr>';
} while ($row = mysql_fetch_assoc($results));

echo "</table><hr>";

关于php - mysql_fetch_array 跳过第一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18258675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com