Pagination Help!!

Discussion in 'PHP' started by badmasketa, Jun 22, 2008.

  1. #1
    I have a pagination script here:

    <?
    
    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM wallpapers"),0); 
    
    $total_pages = ceil($total_results / $max_wp_results); 
    
    echo "<b><strong>";
    echo "<center>Pages</br>"; 
    
    // Build Previous Link 
    if($page > 1){ 
        $prev = ($page - 1); 
        echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\";><font color=\"#6699CC\">Previous&nbsp</font></a>"; 
    } 
    
    for($i = 1; $i <= $total_pages; $i++){ 
        if(($page) == $i){ 
            echo "$i&nbsp;"; 
            } else { 
                echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\";>$i</a>&nbsp;"; 
        } 
    } 
    
    // Build Next Link 
    if($page < $total_pages){ 
        $next = ($page + 1); 
        echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\";><font color=\"#6699CC\">Next</font></a>"; 
    }
    
    ?>
    Code (markup):

    Now what i want is

    i want to put this codes into table like this :

    <table border="0" cellpadding="2" cellspacing="2">
        <tr>
          <td align="center" bgcolor="#000000" width="19"><font color="white"><b>1</b></font></td>
          <td width="19">2</td>
          <td width="19">3</td>
          <td width="19">4</td>
          <td width="19">5</td>
          <td>[next]</td>
        </tr>
    </table>
    HTML:

    how can i put those codes into the table above??
     
    badmasketa, Jun 22, 2008 IP
  2. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #2
    <?

    $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM wallpapers"),0);

    $total_pages = ceil($total_results / $max_wp_results);

    echo "<b><strong>";
    echo "<center>Pages</br>";

    // Build Previous Link
    if($page > 1){
    $prev = ($page - 1);
    ?>
    <table border="0" cellpadding="2" cellspacing="2"> <tr> <td align="center" bgcolor="#000000" width="19">
    <?
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\";><font color=\"#6699CC\">Previous&nbsp</font></a> </td> ";
    }

    for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
    echo " <td width=\"19\">$i&nbsp;</td>";
    } else {
    echo " <td width=\"19\"><a href=\"".$_SERVER['PHP_SELF']."?page=$i\";>$i</a>&nbsp;</td>";
    }
    }

    // Build Next Link
    if($page < $total_pages){
    $next = ($page + 1);
    echo " <td width=\"19\"><a href=\"".$_SERVER['PHP_SELF']."?page=$next\";><font color=\"#6699CC\">Next</font></a></td>";
    }
    echo "</tr></table>";
    ?>
     
    kmap, Jun 22, 2008 IP
  3. badmasketa

    badmasketa Well-Known Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #3
    i got error, i.e:
    the pagination table goes to right side of the page..

    i want that pagination table just below the "Pages" text.....

    could you please fixed that??
     
    badmasketa, Jun 22, 2008 IP
  4. Kyriakos

    Kyriakos Active Member

    Messages:
    155
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    51
    #4
    this is my code of my web page pagination:
    <?php
    //Create and print the Navigation bar
    $Nav="";
    
    // if current page is not 1, draw PREVIOUS link
    if ($pg > 1 && $NumberOfPages != 0) {
        printf('<a href="showproducts.php?limit=%s&cid=%s&cat=%s&pg=%s">&lt;</a>', ($limit), ($cid), ($cat), ($pg - 1));
    }
    
    For($i = 1 ; $i <= $NumberOfPages ; $i++) {
        If($i == $pg) {
           $Nav .= "&nbsp;<a href=\"javascript:void(0)\" class=\"selected\"><b>$i</b></a>";
       } else {
            $Nav .= "&nbsp;<a href=\"showproducts.php?limit=".$limit."&cid=$cid&cat=$cat&pg=".$i."\">$i</a>";
        }
    }
    Echo "" . $Nav;
    
    // if current page less than max pages, draw NEXT link
    if ($pg < $NumberOfPages && $NumberOfPages != 0) {
        printf('&nbsp;<a href="showproducts.php?limit=%s&cid=%s&cat=%s&pg=%s">&gt;</a>', ($limit), ($cid), ($cat), ($pg + 1));
    }
    ?>
    PHP:
     
    Kyriakos, Jun 23, 2008 IP
  5. badmasketa

    badmasketa Well-Known Member

    Messages:
    351
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    103
    #5
    i just want the above code i posted to be in html table thats it....

    Anyone please.....
     
    badmasketa, Jun 23, 2008 IP