Is My Pagination Numbering Correct?

Hello,

People, is my code ok below ? Yes ?
It is pagination section. Like Google SERP. Like you see on bottom where you get page links like page 123456789.

Can you tell me which WHILE loop is very much correct. And tell me why you think this one very much good. Ok ?
You will see two WHILEs below. One is commented-out. That one I think least good. And so, I commented-out. What you think so ? Can you tell me ?

//PAGINATION SECTION TO NUMBER THE PAGES AND LINK THEM.
//

$total_pages = ceil($row_count/$max);
$i = '1'; 

//$selfpage = $_SERVER['PHP_SELF'];
$selfpage = basename(__FILE__,''); //Echoes: url_encode_Template.php. Does not fetch the url $_REQUEST params.
$path = rawurlencode($selfpage);
$query_string_1 = '?find=' .urlencode($find) .'&tbl=' .urlencode($tbl) .'&col=' .urlencode($col) .'&max=' .intval($max);

//WHICH WHILE LOOP IS BEST ?
while($i<=$total_pages)
{
	$query_string_2 = '&page=' .intval($i);
	$url = $path .htmlentities($query_string_1) .htmlentities($query_string_2); //Full URL With $_REQUEST params: https://localhost/Templates/url_encode_Template.php?find=keyword&tbl=links&col=keyword&max=100&page=1

	if($page == $i)
	{
		echo '<a href=' .'"' .$url .'"' .'>' .'<b>' .intval($i) .'</b>' .'</a>';
	}
	else
	{
		echo '<a href=' .'"' .$url .'"' .'>' .intval($i) .'</a>';
	}
	$i++;
}

echo '<br>';
echo '<b>'; echo __LINE__; echo '</b>'; echo '<br>';

/*
$i = '1';
//WHICH WHILE LOOP IS BEST ?
while($i<=$total_pages)
{
	$query_string_2 = '&page=' .intval($i);
	
	if($page == $i)
	{
		echo '<a href=' .'"' ."$path" .htmlentities($query_string_1) .htmlentities($query_string_2) .'"' .'>' .'<b>' .intval($i) .'</b>' .'</a>';
	}
	else
	{
		echo '<a href=' .'"' ."$path" .htmlentities($query_string_1) .htmlentities($query_string_2) .'"' .'>' .intval($i) .'</a>';
	}
	$i++;
}
*/
?>

Can you letting me know which WHILE is best out of the two ? Yes ?
And, can you amend this code if you deem not good enough for XSS attack, javascript attack, etc. all hacker bad man attacks.

Neither as you use the query to determine the number of pages to display when using pagination.

Example:

$sql = 'SELECT * FROM myTableName WHERE page=:page ORDER BY date_updated DESC LIMIT :perPage OFFSET :blogOffset';

and you figure out the number of pages that you want to display, the offset and the current page location on the page.

Example:

/*
 * Using pagination in order to have a nice looking
 * website page.
 */

if (isset($_GET['page']) && !empty($_GET['page'])) {
    $current_page = urldecode($_GET['page']);
} else {
    $current_page = 1;
}

$per_page = 3; // Total number of records to be displayed:
$total_count = CMS::countAllPage('blog'); // Total Records in the db table:


/* Send the 3 variables to the Pagination class to be processed */
$pagination = new Pagination($current_page, $per_page, $total_count);


/* Grab the offset (page) location from using the offset method */
$offset = $pagination->offset();
//echo "<pre>" . print_r($offset, 1) . "</pre>";
//die();
/*
 * Grab the data from the CMS class method *static*
 * and put the data into an array variable.
 */
$cms = CMS::page($per_page, $offset,'blog');
    public function __construct($page=1, $per_page=20, $total_count=0) {
        $this->current_page = (int) $page;
        $this->per_page = (int) $per_page;
        $this->total_count = (int) $total_count;
    }

    public function offset(): float|int
    {
        return $this->per_page * ($this->current_page - 1);
    }

    #[Pure] public function total_pages(): float|bool
    {
        return ceil($this->total_count / $this->per_page);
    }

The above is just pseudo code (kind of), but there are plenty of good tutorials on pagination.

Thread closed as the OP is banned.