dandaman96 Posted January 23, 2010 Share Posted January 23, 2010 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 Link to comment https://forums.phpfreaks.com/topic/189495-mysql_fetch_assocresult-reset-pointer-mysql_data_seek-causes-page-to-fail/ Share on other sites More sharing options...
dandaman96 Posted January 23, 2010 Author Share Posted January 23, 2010 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... Link to comment https://forums.phpfreaks.com/topic/189495-mysql_fetch_assocresult-reset-pointer-mysql_data_seek-causes-page-to-fail/#findComment-1000246 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.