Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts

    mysql_data_seek not working on first record

    I have a mysql recordset below:

    PHP Code:
    $qryRsltT0 mysql_query($barryq,$dblinkT0);
    while (
    $row mysql_fetch_array($qryRsltT0)){
    $pcount++;
    mysql_data_seek($qryRsltT0,$q);
    echo 
    $row['name'];
    if (
    $pcount==2) {break;}

    This returns:
    Person A
    Person B
    Person C
    Person D

    Those are all 4 of my records. However, using mysql_data_seek, the first loop of returning the recordset always chooses the first record, and then gets the $q index correct after the first loop

    PHP Code:
    $pcount=0;
    $q=2;
    $qryRsltT0 mysql_query($barryq,$dblinkT0);
    while (
    $row mysql_fetch_array($qryRsltT0)){
    $pcount++;
    mysql_data_seek($qryRsltT0,$q);
    echo 
    $row['name'];
    if (
    $pcount==2) {break;}

    This returns:
    Person A
    Person C

    How would I make the first round of looping correct to get it to pick the $q index?

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    You need to seek before you start looping.

    Code:
    mysql_data_seek($qryRsltT0,$q);
    
    while ($row = mysql_fetch_array($qryRsltT0)){

  • Users who have thanked MattF for this post:

    mathceleb (11-10-2010)

  • #3
    Regular Coder
    Join Date
    Mar 2010
    Posts
    235
    Thanks
    39
    Thanked 6 Times in 6 Posts
    Thanks, that worked.


  •  

    Posting Permissions

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