SitePoint Sponsor

User Tag List

Results 1 to 14 of 14
  1. #1
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    You're a genious if you can figure this out

    The problems: Every page has shows the same user results & last page is labeled 6.2 instead of 6 or 7.
    Check out the //Paginate part of script.

    PHP Code:
    <?php
    // PERFORM QUERY & POPULATE TABLE
     
    $query 'SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users' ' ORDER by ipoints DESC LIMIT 0 , 15' ;
     
    $result mysql_query($query) or die('Query failed: ' mysql_error());

    if (
    $db->num_rows($result))
    {
        while (
    $line mysql_fetch_array($resultMYSQL_ASSOC)) {
         echo 
    "\t<tr>\n";
    ?>

        <td class="tcl" scope="col"><?php echo '<a href="iprofile.php?id='.$line['id'].'">'.pun_htmlspecialchars($line['username']).'</a>' ?></td>
        <td class="tc2" scope="col"><?php echo $line['iwins']; ?></td>
        <td class="tc3" scope="col"><?php echo $line['ilosses']; ?></td>
        <td class="tc4" scope="col"><center><?php echo $line['ipoints']; ?></center></td>        

    <?php
              
    }
        echo 
    "\t</tr>\n";
    }
    echo 
    "</table>\n";
    //END TABLE


    //BEGIN PAGINATE
    $result $db->query('SELECT COUNT(id)-1 FROM '.$db->prefix.'users') or error('Unable to fetch total user count'__FILE____LINE__$db->error());
     
    $query_rows $db->result($result);

    $num_pages ceil($query_rows) / 15;

    if (
    intval($_GET['p']) && $_GET['p'] <= $num_pages
    $cur_page $_GET['p'];

    $link_to 'ladder2.php?foo=bar';

    echo 
    '<center>Page:'.paginate($num_pages$cur_page$link_to).'</center>';
    //END PAGINATE

    ?>
    *the page can be seen here

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2007
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shouldn't
    PHP Code:
    ceil($qeury_rows) / 15
    be
    PHP Code:
    ceil($query_rows/15); 
    ?

    My guess is you have something like 93 rows and 93/15 = 6.2. Am I right?

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code php:
    $p=(int)$_GET['p'];
    $query = 'SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users' . ' ORDER by ipoints DESC LIMIT $p , 15' ;
    Code php:
    $num_pages = ceil($query_rows / 15);
    Saul

  4. #4
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tim912 View Post
    Shouldn't
    PHP Code:
    ceil($qeury_rows) / 15
    be
    PHP Code:
    ceil($query_rows/15); 
    ?

    My guess is you have something like 93 rows and 93/15 = 6.2. Am I right?
    Yea you are right.


    php_daemon:
    Looks like a very good idea, I will try this now.
    Thanks.

  5. #5
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, it is working a little better now. The problem is the way its displaying results. Its using some of the same people on different pages, and displaying randomly.
    Check out what I mean here

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The problem is that all of them have 0 points. Add the secondary order by name to keep it consistent.

    Code sql:
    SELECT id, username, iwins, ilosses, ipoints 
    FROM punbb2_users 
    ORDER BY ipoints, DESC username ASC
    LIMIT $p , 15
    Last edited by php_daemon; May 24, 2007 at 16:03. Reason: missing comma
    Saul

  7. #7
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm it's not letting me include the order by username ASC

    PHP Code:
    $query 'SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users' ' ORDER by ipoints DESC username ASC LIMIT '.$p.', 15' 

  8. #8
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oops, sorry a comma missing there:
    PHP Code:
    $query 'SELECT id, username, iwins, ilosses, ipoints FROM punbb2_users' ' ORDER by ipoints DESC, username ASC LIMIT '.$p.', 15' 
    Saul

  9. #9
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Comma after DESC worked.

    Okay I think the problem is the limit clause because it may show the same username on seperate pages no matter how they are ordered. I think it is based on the LIMIT clause.

    Oh, I see what it is doing. It is simply getting rid of the top user and including the 15 for the same page again, each new page.
    Last edited by t0WL337; May 24, 2007 at 16:11. Reason: edted

  10. #10
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You're absolutely right, that's my bad, the $p should be:
    PHP Code:
    $p=(int)$_GET['p']*15
    Saul

  11. #11
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sweet man, that worked well.

    The first page though, does not actually show the first 15 users? Why is that?

  12. #12
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh, yes, the paging is all wrong. Try this,

    PHP Code:
    $p=isset($_GET['p'])?(int)($_GET['p']-1)*15:0
    Saul

  13. #13
    SitePoint Zealot t0WL337's Avatar
    Join Date
    Mar 2007
    Location
    Ottawa, Ontario!
    Posts
    149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Php_daemon, you truly are a genious! Thank you so very much for your help.

  14. #14
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Nah, should have done it right in the very first reply.

    You're welcome.
    Saul


Bookmarks

Posting Permissions

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