[RESOLVED] SQL Query not showing the first record only-VBForums
Results 1 to 5 of 5

Thread: [RESOLVED] SQL Query not showing the first record only

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    851

    Resolved [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 -->

  2. #2
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,331

    Re: SQL Query not showing the first record only

    Remove $row=mysql_fetch_array($res); from below $res = mysql_query($sql,$con);

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    851

    Re: SQL Query not showing the first record only

    thanks,
    its working now, but what was the logic behind this ?

  4. #4
    PowerPoster
    Join Date
    May 2002
    Posts
    25,976

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2004
    Location
    Quetta-Pakistan
    Posts
    851

    Re: SQL Query not showing the first record only

    OK.. thanks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.