Forum Moderators: coopster
I have a nested loop, like this:
while(x) {
echo $a;
do {
echo $rowvalue;
} while (loop through recordset);
}
The thing I'm having trouble with is that $a should be a value from the record AFTER the current record that's being looped through. In other words, it'll grab a value from the next row before actually looping to it. I know that in this example it doesn't make sense, but my actual nested tables and the reason I'm doing this is a bit complicated, but just trust that it's necessary so that I don't have to explain it!
So, I'm trying this code:
while(x) {
echo $a;
do {
echo $rowvalue;
$a = $nextrowvalue;
} while (loop through recordset);
}
I know that I can use mysql_data_seek to go to a specific row in my result set, but my problem is that I don't know how to tell which row I'm currently on... Is there a way to do that? I'm currently fiddling with placing a variable in my loop to help count as I cycle through the records. I'm using like:
mysql_data_seek($result, $next);
$row_result = mysql_fetch_assoc($result);
$a = $nextrowvalue;
mysql_data_seek($result, $current);
$row_result = mysql_fetch_assoc($result);
But no luck there.
<?php
function mysql_pointer_position($result_set) {
$num_rows = mysql_num_rows($result_set);
$i = 0;
while($result = mysql_fetch_array($result_set)) {
$i++;
}
$pointer_position = $num_rows - $i;//Return pointer to original position
if($pointer_position <= $num_rows - 1) {
mysql_data_seek($result_set, $pointer_position);
}
return $pointer_position;
}
?