mysql_fetch_array跳过第一行 [英] mysql_fetch_array skipping first row

查看:77
本文介绍了mysql_fetch_array跳过第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:感谢快速回复的人们 - 我最终切换到了mysql_fetch_assoc(),并使用了do ...而我很好。

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

I am using this same process to create and populate tables - Everything works fine except that the first row is skipped in every table. Could use another pair of eyes as I can't seem to pinpoint the issue. Thanks in advance.

   $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两次之前循环,然后循环一次。

You are calling mysql_fetch_array twice... once before the loop then once while looping.

如果您需要一个种子行来构建标题行,您可能会更好地使用do .. while循环。

If you need a seed row for use in building your header row you might be better served with a do.. while loop here.

$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>";

这篇关于mysql_fetch_array跳过第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆