Hello everyone,

i met a real big problem and i'll really appreciate if someone can help me on this.
i know there's something wrong in my file but i can't locate this problem.
so the problem is i can't browse pages..for example i have 19 pages when i click on page 2 or three or...till 19 it doesn't browse anything it still on page one.
the file causing that is browse.php

here's the whole file :

<?php
/*
This script handles the browse function creating
a previous and next link if appropriate as well
as creating page numbers to allow the user to link
to a page out of order
*/

// The PREVIOUS page begins at the current offset LESS the number of ROWS per page
$previous_offset = $offset - ROWS;


// The NEXT page begins at the current offset PLUS the number of ROWS per page
$next_offset = $offset + ROWS;


// format query string depending on if
// mod_rewrite is on of off
if (REWRITE_URLS == 1) {
    $browse_script_name = $browse_script_name . "?offset=";
} else {
    $browse_script_name = $browse_script_name . "&offset=";
}


// show the row numbers that are being viewed like this:
// "10 - 15 of 20"
$browse_info = "
<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
	<tr>
		<td align=\"center\" valign=\"middle\" style=\"white-space: nowrap; font-weight: bold;\">Showing " . ($offset + 1) . " - " . ($row_counter + $offset) . " of $rows_found Articles</td>
	</tr>
</table>";






// Are there any PREVIOUS Pages?
if ($offset > 0)
{
	// yes, so create a link
	$browse_previous = "
	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
			<td style=\"white-space: nowrap;\"><a class=\"browse\" href=\"$browse_script_name" . $previous_offset . $browse_string . "\">&#171; Previous</a></td>
		</tr>
	</table>";
	
} else {

	// no there is no previous page so dont make a link
	$browse_previous = "
	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
			<td style=\"white-space: nowrap;\">&#171; Previous</td>
		</tr>
	</table>";
	
}// end if ($offset > 0)




// are there any NEXT pages
if ((ROWS != false) && ($rows_found > $next_offset))
{
	// yes so create a link
	$browse_next = "
	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
			<td style=\"white-space: nowrap;\"><a class=\"browse\" href=\"$browse_script_name" . $next_offset . $browse_string . "\">Next &#187;</a></td>
		</tr>
	</table>";
	
} else {

	// no so dont create a link
	$browse_next = "
	<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">
		<tr>
			<td style=\"white-space: nowrap;\">Next &#187;</td>
		</tr>
	</table>";
	
}// end if (($row != false) && ($rows_found > $next_offset))



// initialize $browse_page
$browse_page = "
<table border=\"0\" cellpadding=\"2\" cellspacing=\"0\">
	<tr>
	    <td>";
				
// output page numbers as links
for ($x = 0, $page = 1; $x < $rows_found; $x += ROWS, $page++)
{	 
	// is this the current page?
	if ($x < $offset || $x > ($offset + ROWS - 1))
	{
		// no, so make a link
		$browse_page .= " <a class=\"browse\" href=\"$browse_script_name" . $x . $browse_string . "\">". $page . "</a> ";
			
		
	} else {
	
		// yes, so dont make a link
		$browse_page .= " $page ";
		
		
	}// end if ($x < $offset || $x > ($offset + ROWS - 1))

}// end for ($x = 0, $page = 1; $x < $rows_found; $x += ROWS, $page++)
$browse_page .= "
        </td>
	</tr>
</table>";

?>

Please tell me what's wrong in here?:icon_sad:

Dani AI

Generated

A short diagnostic summary: the symptom (clicking page 2..19 always stays on page 1) means the pagination parameter never reaches or is ignored by the code that renders the results. is right to call out an uninitialized $browse_script_name — if the link target is wrong or the query string gets mangled, the server will see no offset and will fall back to page one. Other frequent causes are an unset/overwritten $offset, ROWS being zero/false, or a double-escaped ampersand in the generated href.

A small, safe pattern to use when building and reading the offset:

$offset = isset($_GET['offset']) ? max(0, (int) $_GET['offset']) : 0;
$base = !empty($browse_script_name) ? $browse_script_name : strtok($_SERVER['REQUEST_URI'], '?');
$sep = (strpos($base, '?') === false) ? '?' : '&';
$url = $base . $sep . 'offset=' . $x . (isset($browse_string) ? $browse_string : '');
$link = htmlspecialchars($url, ENT_QUOTES, 'UTF-8');

A compact checklist to run through (in this order): inspect the page source / devtools and confirm each page link actually contains an offset value (not &amp;amp;offset or a blank href); verify $_GET contains the offset after clicking a link (temporary var_dump($_GET) near the top of the script); ensure $offset is read once and not reset later; confirm ROWS is defined and greater than zero and $rows_found is correct; check $browse_string for leading ampersands or encoding issues; confirm REWRITE_URLS mode matches the URL format being generated.

Note: building a raw URL and then passing it through htmlspecialchars avoids accidental double-escaping. If the generated hrefs look correct but the page still shows page one, the server-side code is likely overwriting $offset or failing to use it when querying the database.

Not entirely sure if this is the cause, but $browse_script_name does not have a value at the start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.