Hi everybody
i created some pages for news management then i write some codes to put pagination under the fields for each 5 subjects than it tooks to another page for displaying rest of the subjects and everythings is ok but the problem is here i cant display the current page because i create my numbers with for loop, i want to display the current page bold or some things like that for user. this is a page codes . please help me with this problem .

      <table width="800" border="0" align="center" cellspacing="3" summary="2007 Major IT Companies' Profit">
        <tbody>
          <tr>
            <td width="45" height="30" align="center" bgcolor="#35AED9">شناسه</td>
            <td width="215" align="center" bgcolor="#35AED9">تاریخ ثبت خبرنامه</td>
            <td align="center" bgcolor="#35AED9"><span style="color: #FFF">عنوان خبرنامه</span></td>
            <td width="48" align="center" bgcolor="#35AED9">تصویر</td>
            <td width="48" align="center" bgcolor="#35AED9">ویرایش</td>
            <td width="54" align="center" bgcolor="#35AED9">حذف</td>
          </tr>
        </tbody>
      </table>
      <br />
      <span style="color:#000">
<?php 
$nn=5;

$s=mysql_query("select * from news");

$c=mysql_num_rows($s);

if($c%$nn==0)
{
$cc=$c/$nn; 
}
else
{
$cc=$c/$nn+1;   
}
$ss=@$_REQUEST['ss'];

if($ss=="")
{ $sql=mysql_query("select * from news order by id desc limit 5");
  while($result=mysql_fetch_array($sql))
{
$id=$result['id'];   $date=$result['date']; $title=$result['title'];  $pic=$result['pic']; 
$id_code=base64_encode(base64_encode($id));
?> 

      <table width="800" border="0" align="center" cellspacing="3" id="rounded-corner2">
        <tfoot>
        </tfoot>
        <tbody>
          <tr>
            <td width="45" height="30" align="center" bgcolor="#E1E1E1"><?php echo $id ?></td>
            <td width="213" align="center" bgcolor="#E1E1E1"><?php echo $date; ?></td>
            <td width="359" align="center" bgcolor="#E1E1E1" id="thumbnail" >        
<?php  

if( strlen( $title ) < 45 ) {
    echo $title; // if less than 100 chars, show the entire text
} else {
    $cut_text = substr( $title, 0, 45 ); //cut at 100 chars
    $last_space = strrpos( $cut_text, " " ); //find the position of the last space in the 200 chars text
    $short_text = substr( $cut_text, 0, $last_space ); //cut again at the last space
    $end_text = $short_text."..."; // add three dots
    echo $end_text;
}   ?>       
            </td>
            <td width="48" align="center" bgcolor="#E1E1E1" id="thumbnail" >

              <div id="thumbnail">
                <a href="images/<?php echo $pic;?>"><img src="../../images/icon/kview.png" alt="hills" rel="" /></a>            
                <p id="large"></p>
              </div> 
              <div id="large"></div>   
  <div id="background"></div>              <a href="edit.php<?php echo "?id=$id"; ?>" target="_self"></a></td>
            <td width="48" align="center" bgcolor="#E1E1E1"><a href="edit.php<?php echo "?2GQ263Q5=$id_code"; ?>" target="_self"><img src="../../images/icon/user_edit2.png" alt="" title="" border="0" /></a></td>
<td width="54" align="center" bgcolor="#E1E1E1"><a href="delete.php<?php echo "?kcTCxw6B=$id_code"; ?>" class="ask-plain" target="_self"><img src="../../images/icon/trash.png" alt="" title="" border="0" /></a>
</td>

</tr>
</table>  
<?php
}}
else
{
$sql=mysql_query("select * from news order by id desc limit $ss,5 ");
while($result=mysql_fetch_array($sql))
{
$id=$result['id'];   $date=$result['date']; $title=$result['title'];  $pic=$result['pic']; 
?>

      <table width="800" border="0" align="center" cellspacing="3" id="rounded-corner2">
        <tfoot>
        </tfoot>
        <tbody>
          <tr>
            <td width="45" height="30" align="center" bgcolor="#E1E1E1"><?php echo $id ?></td>
            <td width="213" align="center" bgcolor="#E1E1E1"><?php echo $date; ?></td>
            <td width="359" align="center" bgcolor="#E1E1E1" id="thumbnail" >        
<?php  

if( strlen( $title ) < 45 ) {
    echo $title; // if less than 100 chars, show the entire text
} else {
    $cut_text = substr( $title, 0, 45 ); //cut at 100 chars
    $last_space = strrpos( $cut_text, " " ); //find the position of the last space in the 200 chars text
    $short_text = substr( $cut_text, 0, $last_space ); //cut again at the last space
    $end_text = $short_text."..."; // add three dots
    echo $end_text;
}   ?>       
            </td>
            <td width="48" align="center" bgcolor="#E1E1E1" id="thumbnail" >

              <div id="thumbnail">
                <a href="images/<?php echo $pic;?>"><img src="../../images/icon/kview.png" alt="hills" rel="" /></a>            
                <p id="large"></p>
              </div> 
              <div id="large"></div>   
  <div id="background"></div>              <a href="edit.php<?php echo "?id=$id"; ?>" target="_self" title="Edit source file"></a></td>
            <td width="48" align="center" bgcolor="#E1E1E1"><a href="edit.php<?php echo "?2GQ263Q5=$id_code"; ?>" target="_self"><img src="../../images/icon/user_edit2.png" alt="" title="" border="0" /></a></td>
<td width="54" align="center" bgcolor="#E1E1E1"><a href="delete.php<?php echo "?kcTCxw6B=$id_code"; ?>" class="ask-plain" target="_self"><img src="../../images/icon/trash.png" alt="" title="" border="0" /></a>
</td>

</tr>
</table>  
   <?php } }  ?>  <br />
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><p>
        <?php

echo "<br>";echo "<br>";      

* $j=0;
echo"Page numbers : ";
for($i=1;$i<=$cc;$i++)
{
echo"<a href=\"show.php?ss=$j\"><strong>$i</strong></a>";
echo" | ";
$j=$j+$nn;
}}*

?>

</td>
  </tr>
</table>

You should put a test in the for loop to see whether the displayed number is the number of the current page; if yes then you have to have a code for displaying that number (and no link), otherwise you display a link. It is hard to give a snippet of the code since you do not use very descriptive names for variables. I would use names like $current_page, $total_pages, etc and then it would be a bit easier.

I also suggest you use CSS styles for stylink links and current page number. It is more flexible and does not clutter the code.

There is a PEAR class called Pager that does all this for you neatly. Have alook at it:

http://pear.php.net/package/Pager/
http://www.alberton.info/pear_pager_tutorials.html

Maybe you can use it or have a look at the code.

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.