-
Jun 10th, 2014, 05:45 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] SQL Query not showing the first record only
hi,
i wrote the following code, it is showing all records except the first record,
Code:
<table>
<tr>
<th>Username</th>
<th>Full Name</th>
<th>User Level</th>
<th>Action</th>
</tr>
<!-- START PHP Database Connectivity -->
<?php
include '../conn.php';
$sql="Select * from users";
$res = mysql_query($sql,$con);
$row=mysql_fetch_array($res);
?>
<!-- END PHP Database Connectivity -->
<!-- START showing data in table -->
<?php
while ($row=mysql_fetch_array($res))
{
echo "<tr align=\"left\">
<td>" . $row[1] . "</td>
<td>" . $row[3] . "</td>
<td>" . $row[4] . "</td>
<td>" . $row[3] . "</td>
</tr>";
}
?>
<!-- END showing data in table -->
</table>
</div>
<!-- END content div -->
-
Jun 10th, 2014, 07:45 AM
#2
Re: SQL Query not showing the first record only
Remove $row=mysql_fetch_array($res); from below $res = mysql_query($sql,$con);
-
Jun 10th, 2014, 01:58 PM
#3
Thread Starter
Fanatic Member
Re: SQL Query not showing the first record only
thanks,
its working now, but what was the logic behind this ?
-
Jun 10th, 2014, 02:37 PM
#4
Re: SQL Query not showing the first record only
fetch array gets the next line in the returned data... so you were grabbing the first record,... then grabbed the next one when you started the loop... mean time, you didn't do anything with the first record in the first place.
-tg
-
Jun 10th, 2014, 06:30 PM
#5
Thread Starter
Fanatic Member
Re: SQL Query not showing the first record only
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|