Hello,
Does anyone know the code to make a while loop not start at the very first record, but to start at a record you specify?
Thanks,
Jade
While Loops
Moderator: General Moderators
You mentioned records so I assume you are asking about while loops applied to a database result resource.
The mysql_data_seek() fn can move the internal result resource pointer on to the nth row - assuming that you do have a value for $n of course.
If not, post again since I'd need to know more about the specific script.
The mysql_data_seek() fn can move the internal result resource pointer on to the nth row - assuming that you do have a value for $n of course.
If not, post again since I'd need to know more about the specific script.
Well.. usually the idea is to help people help themselves. Have you tried it yourself yet?
Anyway, this is how it goes:
Do you have a copy of the php manual? If not, I'd recommend downloading the version with user comments from php.net. Hope this helps.
Anyway, this is how it goes:
Code: Select all
<?php
// somewhere, somehow, you get/create an integer var to pass to mysql_data_seek()
$pos = 3;
// .. and your result resource ($query) has also been declared..
// next:
mysql_data_seek($query, $pos);
// the while loop now begins from $pos: note that the first row is $pos = 0 and NOT 1
while($result = mysql_fetch_assoc/row/array($query))
{
// ... etc
}
?>