tags:

views:

227

answers:

3

How would I do so that the page I'm on wont be clickable?

$page = (isset($_GET['page']) && is_numeric($_GET['page']) ? (int) $_GET['page'] : 1);

$limit = ($page - 1) * 15; 

$sql = mysql_query("SELECT * FROM log LIMIT $limit, 15");

$totalres = mysql_result(mysql_query("SELECT COUNT(id) AS tot FROM log"),0);
$totalpages = ceil($totalres / 15);

for ($i = 1; $i <= $totalpages; $i++) {
  $pagination .= "<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ";
}

<p><?php echo $pagination ?></p>
+3  A: 
if ($i == $page)
  $pagination .= "$i ";
else
  $pagination .= "<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ";
Kawa
It would be better to use the `$page` variable defined earlier, instead of possibly unset or invalid `$_GET['page']`
Thorarin
You're absolutely right.
Kawa
+1  A: 

with an IF inside the FOR.

if ( $i != $page) {
//your code
} else { //same page
$pagination .= "&nbsp;" . $page . "&nbsp;"
}
dimitris mistriotis
+1  A: 

Just need to modify the for loop to check what the current page is.

for ($i = 1; $i <= $totalpages; $i++) 
{
    if ($i != $page)
        $pagination .= "<a href=\"$_SERVER[PHP_SELF]?page=$i\">$i</a> ";
    else
        $pagination .= " " . $i . " ";
}
Cannonade
You need to change `$i == $page` to != or swap the two lines of code.
Thorarin
fastest gun in the west ... not so much ;) ... Thanks
Cannonade