Using PHP "prev" and "next" to Move Through an Array -


i have 2 "buttons" move array cursor next record or prior record. function using "next" move next (older) record works correctly.

however, function move prior ("prev") record (which toward top of array) not work correctly. suspect may related using "mysqli_data_seek". belief set cursor current location , backtrack previous record. instead cursor continues moves forward if "next" used instead of "prev". how can backtrack prior record?

function return_next_issue()     {     // newer issue  - moves towards top of 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 mysqli_result object in session , shared, might want initialize internal pointer 0 make sure know going seek start. can create variable increments on iteration identify index need , seek previous one.

function return_next_issue() {    // newer issue  - moves towards top of 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 code won't work if $_session['issuenum'] 0 or if greater number of rows available, , therefore code providing.


Comments

Popular posts from this blog

c++ - No viable overloaded operator for references a map -

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - Cannot secure connection using TLS -