Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy page browsing problem

    hi all,

    ok i don't know if any of u can help me in this.



    scenario:


    i am trying to build a page where will only display 6 records(images). so u may ask what if it's more than six? yes..this is what i am trying to do. this page only displays 6 images at one time eventhough it is 100images in the DB. so...there will be page numbers like this forum has <<1 2 3 4...>> and each of these can only display 6 images. so if there are 12 images there should only be 2 pages..<<1 2>>. if there are only 6 images then it would be <<1>>. understand what i am trying to say here?. it's sopmething like a page browser where u can go to any number of page u like and it will display the records there.


    actually..i have the code here.i have done partially of it but it doesn't raelly work like how it is suppose to be. it can go to the page u want but it won't display it out and when u go to the next page or previous the records just don't display. here is the code



    PHP Code:

    $sql 
    "SELECT * FROM tblgallery WHERE username = '" $_GET["username"] . "'";
       
    $rs mysql_query($sql);
       
    $nRows mysql_num_rows($rs);
       
       
    /* Set the default records to be shown per page as 5 */
       
    $pageSize 3;
       
       
    /* Page is not set then set it to page 1 */
       
    if(!isset($_GET["page"])) 
        
    $page 1;
       else
        
    $page $_GET["page"];
       
       
    $startPos $page $pageSize - ($pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10
       
    $sql .= ' LIMIT ' $startPos ', ' $pageSize//now break into paged sections
       
    $rs mysql_query($sql) or die('Error: ' mysql_error());
       
       
        
       echo(
    '<table width="100%" cellspacing="2" border="0" align="center" cellpadding="2">');
       echo(
    ' <tr><td align=right><span class="nav">');
       
       if (
    $page != 1) {
        
    $prev $page 1;
        echo 
    '<span class="nav"><a href="' $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'">&lt;&lt;</a>';
       }
       else
        echo (
    "<span class=\"nav\">&lt;&lt;");
       
       
    $totalPage $nRows $pageSize;
       for(
    $i 1$i <= $totalPage$i++) {
        
    /* inactive page, don't add linking */
        
    if ($i == $page){ echo '&nbsp;' $i;} 
        
    /* page active, add linking */
        
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>';}
       }

       if ((
    $nRows $pageSize) != 0) {
        
    /* inactive page number */
        
    if ($i == $page){ echo '&nbsp;' $i; }
        
    /* active page, linked */
        
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '">' $i '</a>'; }
       }

       if( (
    $nRows - ($pageSize $page)) > 0) {
        
    $next $page 1;
        echo 
    '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $next '">&gt;&gt;</a></span>';
       } 
       else{
        echo 
    "&nbsp;&gt;&gt;</span>";
        echo(
    "</td>");
            echo(
    "</tr>");
          echo(
    "</table>");
       
            echo(
    '<table width="100%" border="0" cellspacing="1" cellpadding="4">');
         while (
    $row mysql_fetch_object($rs)) { 
              echo(
    "<tr><td align=center class=\"bg\" border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td>
          <td align=center border=1><img src=\"$row->pic_Path\" width=\"150\" height=\"120\"></td></tr>"
    );
             }
    //close while 


    the username comes from this which i have posted before:



    PHP Code:

     
    echo("<tr bgcolor=\"#FEDCED\"> 
              <td width=\"12%\">&nbsp;</td>
              <td width=\"6%\">&nbsp;</td>
              <td width=\"82%\"><font face=\"Arial, Helvetica, sans-serif\" size=\"2\" color=\"#104071\"><a href=\"photoUpload.php?username="
    .$_POST['txtUserID']."&mode=list\">-Upload New Photo</a></font></td> 
        </tr>"
    ); 


    i have already corrected the syntax so..it's correct now. but now the focus is on the page browsing. pls help for the last time.....i am going nuts already.
    Warm Regards,
    Mivec

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    you need to change your links to reflect the username in the url.

    PHP Code:
    $username $_GET["username"];
    if (
    $page != 1) { 
        
    $prev $page 1
        echo 
    '<span class="nav"><a href="' $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'&username='.$username.'">&lt;&lt;</a>'
       } 
       else 
        echo (
    "<span class=\"nav\">&lt;&lt;"); 
        
       
    $totalPage $nRows $pageSize
       for(
    $i 1$i <= $totalPage$i++) { 
        
    /* inactive page, don't add linking */ 
        
    if ($i == $page){ echo '&nbsp;' $i;}  
        
    /* page active, add linking */ 
        
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '&username='.$username.'">' $i '</a>';} 
       } 

       if ((
    $nRows $pageSize) != 0) { 
        
    /* inactive page number */ 
        
    if ($i == $page){ echo '&nbsp;' $i; } 
        
    /* active page, linked */ 
        
    else {echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '&username='.$username.'">' $i '</a>'; } 
       } 

       if( (
    $nRows - ($pageSize $page)) > 0) { 
        
    $next $page 1
        echo 
    '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $next '&username='.$username.'">&gt;&gt;</a></span>'
       } 

  • #3
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks miranda..it worked...BUT..not really worked..errmm....how to explain this...nvm...i have attached the print screens into this...i hope that helped my explaination?really hope u can help me.thank you.
    Attached Thumbnails Attached Thumbnails page browsing problem-picerror.gif   page browsing problem-picerror2.gif  
    Warm Regards,
    Mivec

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,062
    Thanks
    4
    Thanked 8 Times in 8 Posts
    the error tells me that it is in how you wrote your pagination code. try this

    PHP Code:
    if(!isset($_GET['page'])){ 
        
    $page 1
    } else { 
        
    $page $_GET['page']; 


    $pageSize 6// define how many rows are shown

    $sql "SELECT * FROM tblgallery WHERE username = '" $_GET["username"] . "'"
    $rs mysql_query($sql); 
    $nRows mysql_num_rows($rs); 
    $startPos = (($page $pageSize) - $pageSize); // Ex: (2 * 10) - 10 = 10 <- data starts at 10 
    $sql .= ' LIMIT ' $startPos ', ' $pageSize//now break into paged sections 
    $rs mysql_query($sql) or die('Error: ' mysql_error()); 

    $username $_GET["username"]; 


    $totalPage ceil($nRows $pageSize);   // Use ceil() to round up.

    if ($page 1) {  
        echo 
    '<span class="nav"><a href="' $_SERVER['PHP_SELF'] . '?mode=list&page='.$prev.'&username='.$username.'">&lt;&lt;</a>';  
    }else { 
        echo (
    "<span class=\"nav\">&lt;&lt;");  
    }

    for(
    $i 1$i <= $totalPage$i++) {      
        if (
    $i == $page){    // inactive page, don't add linking  
            
    echo '&nbsp;' $i;
        } else {      
    // page is active, so add linking  
        
    echo '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $i '&username='.$username.'">' $i '</a>';
        }  
    }  

    if(
    $page $totalPage) {   
        
    $next $page 1;  
        echo 
    '&nbsp;<a href="' $_SERVER['PHP_SELF'] . '?mode=list&page=' $next '&username='.$username.'">&gt;&gt;</a></span>';  
       } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •