使用PHP“prev”和“next”来移动数组

I have two "buttons" to move the array cursor to the next record or to the prior record. The function using "next" to move to the next (older) record works correctly.

However, the function to move to the prior ("prev") record (which is toward the top of the array) does not work correctly. I suspect that may be related to using "mysqli_data_seek". My belief was that it would set the cursor to the current location and then backtrack to the previous record. Instead the cursor continues to moves forward as if "next" was used instead of "prev". How can I backtrack to the prior record?

function return_next_issue()
    {
    // Newer Issue  - Moves up towards the top of the array.
    // mysqli_data_seek($_SESSION['result'], 0);
    while($row=mysqli_fetch_array($_SESSION['result'], MYSQL_NUM))
            {
                if($_SESSION['issuenum'] == $row[0]) 
                    {                                                       
                        break;
                    }   
            }   
    prev($_SESSION['result']);
    $row=mysqli_fetch_row($_SESSION['result']); 
    return $row[0];
    } 

since the mysqli_result object is in the session and shared, you might want to initialize the internal pointer to 0 to make sure you know you are going to seek from the start. You can also create a variable that increments over the iteration to identify the index you need and seek for the previous one.

function return_next_issue()
{
   // Newer Issue  - Moves up towards the top of the array.
   $i = 0;
   mysqli_data_seek($_SESSION['result'], 0);
   while($row=mysqli_fetch_array($_SESSION['result'], MYSQL_NUM))
   {
      if($_SESSION['issuenum'] == $row[0]) 
      {                                                       
         break;
      }   
      $i++;

   }   
   mysqli_data_seek($_SESSION['result'], $i - 1);
   $row=mysqli_fetch_row($_SESSION['result']); 
   return $row[0];
}

Please note that your code won't work if $_SESSION['issuenum'] is 0 or if is greater than the number of rows available, and therefore so do the code I am providing.