php - mysql_fetch_array skipping first row -
edit : quick responses guys - ended switching mysql_fetch_assoc() , using do...while , go.
i using same process create , populate tables - works fine except first row skipped in every table. use pair of eyes can't seem pinpoint issue. in advance.
$query = "select * members"; $results = mysql_query($query); $row = mysql_fetch_array($results); //echo <table> start , 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>";
you calling mysql_fetch_array twice... once before loop once while looping.
if need seed row use in building header row might better served do.. while loop here.
$query = "select * members"; $results = mysql_query($query); $row = mysql_fetch_assoc($results); //echo <table> start , headings; { 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>";
Comments
Post a Comment