I’m currently using the following snippet for an improvised pagination system. Unfortunately, I’ve run into a bit of a roadblock. The variable $result->info['pages'] is returned by a remote API and is the number of pages available. The variable $result->info['page'] is the currently visible page. The links appear as expected an in the right place, but they act as if the page is ALWAYS 1 (The ‘1’ link always shows as plaintext, everything else always shows as a link). However, if I echo the $result->info['page'], it shows the correct page number, and the information displayed is correct. Thoughts as to what I might be doing wrong?
<?php if ($result->info['pages'] > '1') {
if ($result->info['page'] != '1') {
echo '<a onClick="location.replace(\'?page=' . --$result->info['page'] . '\');">Prev</a> ';
} else {
echo 'Prev ';
}
for ($i = 1; $i <= $result->info['pages']; $i++) {
if ($i == $result->info['page']) {
echo $i . ' ';
} else {
echo '<a onClick="location.replace(\'?page=' . $i .'\');">' . $i . '</a> ';
}
}
if ($result->info['page'] != $result->info['pages']) {
echo '<a onClick="location.replace(\'?page=' . ++$result->info['page'] . '\');">Next</a>';
} else {
echo 'Next';
}
} ?>
You don’t need to modify
--$result->info['page'], just replace it with($result->info['page'] - 1)and everything will go wellhttp://ideone.com/WiGh4