...

View Full Version : pagination



jokerboy123
05-19-2011, 03:56 AM
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]

Fumigator
05-19-2011, 03:30 PM
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.

bullant
05-19-2011, 10:48 PM
plua this thread is a cross post of this thread. (http://www.codingforums.com/showthread.php?p=1092249&highlight=pagination#post1092249)

oracleguy
05-19-2011, 11:34 PM
I am closing this thread. See other thread: http://www.codingforums.com/showthread.php?t=227259



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum