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

Thread: pagination

  1. #1
    New Coder
    Join Date
    May 2011
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    pagination

    Hey ladies n germans, just wondering if i can get some help, im getting a mysql syntax error but cant understand why, what im trying to do with this code is paginate, iv gotten pagination working befor but this is a different code and im just unsure how to work it out, this code is used to display the 5 most recent users or an entire list or a search, depending on what the user has clicked.

    [CODE]
    function get_users($name="",$gender="",$age_range="",$offset,$entries_per_page) {
    $name = clean($name,80);

    $connection = mysql_open();

    $query =
    "select SQL_CALC_FOUND_ROWS id, username, realname, gender, birthdate, joindate, email, " .
    "(year(curdate()) - year(birthdate)) " .
    " - (right(curdate(),5) < right(birthdate,5)) as age " .
    "from yusers where 1 ";
    if ($name) {
    $query .= "and (username like '%$name%' or realname like '%$name%') ";
    }
    if ($gender) {
    $query .= "and gender = '$gender' ";
    }
    $query .= "order by id";
    $query .= "LIMIT $offset, $entries_per_page";
    //print "$query<br>\n";

    // Find total number of rows, ignoring pagination, using SQL_CALC_FOUND_ROWS
    $r = mysql_query("SELECT FOUND_ROWS()", $connection)
    or show_error();
    $r = mysql_fetch_array($r);
    $num_entries = $r[0];

    $result = mysql_query($query,$connection) or show_error();

    if ($age_range) {
    list($lower,$upper) = preg_split("/-/", $age_range);
    }
    $users = array();
    while ($user = mysql_fetch_array($result)) {
    if ($age_range == "" ||
    ($lower <= $user['age'] && $user['age'] <= $upper)) {
    $users[] = $user;
    }
    }

    mysql_close($connection) or show_error();
    return array($users,$num_entries);
    }
    [CODE]

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I think the reason you don't have any replies yet is because 1) you didn't wrap your code (though you did make an effort to-- the closing tag is wrong) and 2) you didn't tell us what your code is doing wrong.

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    plua this thread is a cross post of this thread.

  • #4
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    I am closing this thread. See other thread: http://www.codingforums.com/showthread.php?t=227259
    OracleGuy


  •  

    Posting Permissions

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