Jump to content

mysql_fetch_assoc($result) reset pointer. mysql_data_seek() causes page to fail


dandaman96

Recommended Posts

First off, hello.  This is my first post on here.  I've been on google for the last couple of hours, searching in vain, and I saw this site recommended over and over again.  So, here I am.

 

What I'm trying to do should be pretty simple.  I'm looping through a query result multiple times.

 

What I started with... page loads, but only the first loop is executed.

while ($check = mysql_fetch_assoc($result)){
  if(($_SESSION['label']) == $check['label']){
     $labelCheck = 1;
    }
}

while ($row = mysql_fetch_assoc($bpUsersResult)){
  echo $row['label'];
}

So, it sees that the right 'label' is in the array and correctly sets $labelCheck to 1, but then it doesn't echo anything...  Which I would expect as when I run through the first loop, the array pointer moves to the end of the array and there is nothing left for the second loop to go through.

 

So I tried....

while ($check = mysql_fetch_assoc($result)){
  if(($_SESSION['label']) == $check['label']){
     $labelCheck = 1;
    }
}

mysql_data_seek($result,0);  //reset pointer

while ($row = mysql_fetch_assoc($bpUsersResult)){
  echo $row['label'];
}

 

And I get nothing...  the page will not even reload.  It seems like it times out. 

 

I'm stumped.  What am I missing here? 

 

Thanks,

Dan

I guess I had to see the question for myself to see the stupid mistake I was making......

 

I had mysql_close() before the mysql_data_seek() and it didn't work... imagine that.

 

Well... this question is resolved.  But, now that I've found this site, I'm sure I'll be back again. 

 

Later,

Dan

 

This is what ended up working...

while ($check = mysql_fetch_assoc($result)){
  if(($_SESSION['label']) == $check['label']){
     $labelCheck = 1;
    }
}

mysql_data_seek($result,0);  //reset pointer

while ($row = mysql_fetch_assoc($bpUsersResult)){
  echo $row['label'];
}
mysql_close();  // hey... imagine that... you can't close before you're done...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.