A quick reminder first.
globalize() automatically casts the variables you pass it with the type from the keyword.
e.g.
PHP Code:
'pagenumber' => INT
So there is no reason afterwords to use intval().
The following chunk of code is from my vBulletin Member Album hack. It has a page browse system, and also sorting options, like DESC or ASC, by username, etc.
You should be able to use this script as a guideline for making yours work:
PHP Code:
$perpage = $vboptions['album_perpage'];
$pertr = $vboptions['album_pertr'];
globalize($_GET, array(
'sort' => STR,
'order' => STR,
'ltr' => STR,
'page' => INT
));
// Verify arguments
///////////////////////
$type = $_REQUEST['type'] ? $_REQUEST['type'] : 1;
if ($sort)
{
$valid_sort = array(
'posts',
'joindate',
'dateline',
'username'
);
if (!in_array($sort, $valid_sort))
$sort = 'posts';
}
else
{
$sort = 'posts';
}
if ($order)
{
$valid_order = array(
'desc',
'asc'
);
if (!in_array($order, $valid_order))
$order = 'desc';
}
else
{
$order = 'desc';
}
// Build letter list
////////////////////////
$currentletter = '#';
$linkletter = urlencode('#');
eval('$letterbits = "' . fetch_template('album_letter') . '";');
for ($i=65; $i < 91; $i++)
{
$currentletter = chr($i);
$linkletter = &$currentletter;
$show['selectedletter'] = iif($ltr == $currentletter, true, false);
eval('$letterbits .= "' . fetch_template('album_letter') . '";');
}
if ($ltr != '')
{
if ($ltr == '#')
{
$condition = " AND username NOT REGEXP(\"^[a-zA-Z]\")";
}
else
{
$ltr = chr(intval(ord($ltr)));
$condition = ' AND username LIKE("' . addslashes_like($ltr) . '%")';
}
$leftjoin = " LEFT JOIN ".TABLE_PREFIX."user USING (userid)";
}
// Query: count rows
////////////////////////
$result = $DB_site->query_first("
SELECT COUNT(*) AS count
FROM ".TABLE_PREFIX."".($type == 2 ? 'usertextfield' : 'customprofilepic')."$leftjoin
WHERE ".($type == 2 ? "signature!=''" : 'visible=1')."$condition
");
// Build page scope
///////////////////////
$pagenumber = $page > 0 ? $page : 1;
$rows = $result['count'];
$pages = ceil($rows / $perpage);
if ($pagenumber < 1)
{
$pagenumber = 1;
}
else if ($pagenumber > $rows)
{
$pagenumber = $rows;
}
$minlimit = ($pagenumber - 1) * $perpage+1;
$maxlimit = ($pagenumber) * $perpage;
if ($maxlimit > $rows)
{
$maxlimit = $rows;
$minlimit = $minlimit > $rows ? $rows-$perpage : $minlimit;
}
$minlimit = $minlimit <= 0 ? 1 : $minlimit;
$pagenav = construct_page_nav(
$rows,
"album.php?$session[sessionurl]type=$_REQUEST[type]",
"&pp=$perpage<r=$ltr&sort=$sort&order=$order"
);
// Request: profile picture
///////////////////////////////
if ($type == 1)
{
// Query: fetch profile pictures
////////////////////////////////////
$images = $DB_site->query("
SELECT user.userid, dateline,
comment, user.username, user.usertitle,
user.joindate, user.usergroupid
FROM ".TABLE_PREFIX."customprofilepic
LEFT JOIN ".TABLE_PREFIX."user USING (userid)
WHERE visible=1
$condition
ORDER BY $sort $order
LIMIT " . ($minlimit-1) . ", $perpage
");
$type = 'image';
$count = 1;
$rows = $DB_site->num_rows($images);
if (!$rows)
{
eval('$album_list = "' . fetch_template('album_'.$type.'_list') . '";');
}
else
{
while ($image = $DB_site->fetch_array($images))
{
$image['musername'] = fetch_musername($image);
$image['comment'] = fetch_censored_text($image['comment']);
eval('$album_list .= "' . fetch_template('album_image_list') . '";');
if ($count == $pertr && $count != $rows)
$count = 0;
$count++;
}
while ($count != 1 && $count <= $pertr)
{
eval('$album_list .= "' . fetch_template('album_image_list') . '";');
$count++;
}
}
}
Some of the code in there, like the letters portion and $type variable, don't apply in your case.
Use the $perpage and $pertr variables to control how many images are shown per page, and how many of that page are shown per row.
I use the following template with vB conditionals to show the images.
album_image_list
HTML Code:
<if condition="$rows">
<if condition="$count == 1">
<tr>
</if>
<if condition="$image">
<td width="25%" class="<if condition="$count%2 == 0">alt1<else />alt2</if>" valign="top">
<table cellspacing="0" cellpadding="0" width="100%">
<tr>
<td valign="top" style="width: 1px; padding-left: 20px"><a href="member.php?$session[sessionurl]u=$image[userid]"><img src="./image.php?u=$image[userid]&type=pthumb" border="0" /></a></td>
<td valign="top" style="padding-left: 20px"><a style="font-size:14pt" href="member.php?$session[sessionurl]u=$image[userid]">$image[musername]</a><br /><span class="smallfont">$image[usertitle]<br /><br /><i>$image[comment]</i></span></td>
</tr>
</table>
</td>
<else />
<td width="25%" class="alt1"></td>
</if>
<if condition="$count == $pertr">
</tr>
</if>
</if>
Hope this helps.