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.