First Row Is Not Present...??

Discussion in 'Databases' started by timallard, May 5, 2009.

  1. #1
    I'm doing a simple query and for some reason my first row is being omitted. how come?

    $queryTownA = "SELECT * FROM towns WHERE letter='A' ORDER BY tname ASC";
    $resultTownA = mysql_query($queryTownA) or die(mysql_error());
    $rowTownA = mysql_fetch_array($resultTownA);

    Then Below


    <ul>
    <?php while($rowA = mysql_fetch_array($resultTownA)){ ?>
    <li><a href="town.php?tid=<?php echo $rowA['tid']; ?>"><?php echo $rowA['tname']; ?></a></li>
    <?php }; ?>
    </ul>


    My results are working but the first row is not there..

    MISSING TOWN HERE
    Acton
    Acushnet
    Adams

    any ideas? thanks!!!
     
    timallard, May 5, 2009 IP
  2. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #2
    OK - i just solved my own problem by removing this: $rowTownA = mysql_fetch_array($resultTownA);from my query string.

    My new question is why would this omitt the first row?
     
    timallard, May 5, 2009 IP
  3. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #3
    Basically you are fetching the array once and then looping through it. The first time you fetch it, you are removing the first row.

    Remove this:

    $rowTownA = mysql_fetch_array($resultTownA);

    From the top section.
     
    jestep, May 5, 2009 IP
  4. timallard

    timallard Well-Known Member

    Messages:
    1,634
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    158
    #4
    Thank you very much. I would +rep you but have done recently in the past. I am learning!! :)
     
    timallard, May 5, 2009 IP