wolfe
01-16-2008, 12:56 AM
say i have a page with lists of threads that cross over pages
example at the moment i have got it showing
1
2
3
4
5
6
etc
and its 40 perpage
but once it reaches 40 and i change to the next page it starts from 1 again instead of
41
42
43
etc
can anyone help me with this problem
Opserty
01-16-2008, 11:19 AM
Multiply the "per page" by the "page number - 1". Then add the result on to your increment counter or w/e you are using to count.
wolfe
01-16-2008, 11:22 AM
m8 can u give me the php to do this my counter has packed up its now showing -39 and -80
thx in advance :P
Opserty
01-16-2008, 12:38 PM
Well it depends on your script...
// $perpage - stores number of items perpage make sure you use intval() on it somewhere
// $curpage - current page number make sure you use intval() on it somewhere
if($curpage != 0)
{
$startfrom = $perpage * ($curpage - 1);
}
else
{
$startfrom = 1;
}
Something along those lines.
wolfe
01-16-2008, 02:01 PM
heres my code page nav works etc just need to get the counter working can i show me with the full code $count is the varible i will be using to add a number to the front of each thread.
thx in advance :P
<?php
// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);
// #################### DEFINE IMPORTANT CONSTANTS #######################
define('NO_REGISTER_GLOBALS', 1);
define('THIS_SCRIPT', 'index'); // change this depending on your filename
// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array(
);
// get special data templates from the datastore
$specialtemplates = array(
'userstats'
);
// pre-cache templates used by all actions
$globaltemplates = array(
'INDEX',
'index_threadbit'
);
// pre-cache templates used by specific actions
$actiontemplates = array(
);
// ######################### REQUIRE BACK-END ############################
require_once('./global.php');
require_once(DIR . '/includes/functions_bigthree.php');
function timeDiff($timestamp,$detailed=false){
$now = time();
$diff = ($action == 'away' ? $timestamp - $now : $now - $timestamp);
# Set the periods of time
$periods = array("s", "m", "h", "d", "w");
$lengths = array(1, 60, 3600, 86400, 604800);
# Go from decades backwards to seconds
$i = sizeof($lengths) - 1; # Size of the lengths / periods in case you change them
$time = ""; # The string we will hold our times in
while($i >= 0) {
if($diff > $lengths[$i-1]) { # if the difference is greater than the length we are checking... continue
$val = floor($diff / $lengths[$i-1]); # 65 / 60 = 1. That means one minute. 130 / 60 = 2. Two minutes.. etc
$time .= $val ."". $periods[$i-1].($val > 1 ? '' : ' '); # The value, then the name associated, then add 's' if plural
$diff -= ($val * $lengths[$i-1]); # subtract the values we just used from the overall diff so we can find the rest of the information
if(!$detailed) { $i = 0; } # if detailed is turn off (default) only show the first set found, else show all information
}
$i--;
}
# Basic error checking.
if($time == "") {
return "Error-- Unable to calculate time.";
} else {
return $time.$action;
}
}
// ################################################## #################
// ######################## START MAIN SCRIPT ########################
// ################################################## #################
$array = "59,63,64,69,72";
// Default page variables
$perpage = $vbulletin->input->clean_gpc('r', 'perpage', TYPE_UINT);
$pagenumber = $vbulletin->input->clean_gpc('r', 'pagenumber', TYPE_UINT);
$sortfield = $vbulletin->input->clean_gpc('r', 'sortfield', TYPE_STR);
$sortorder = $vbulletin->input->clean_gpc('r', 'sortorder', TYPE_STR);
// set defaults and sensible values
if ($sortfield == '')
{
$sortfield = 'age';
}
if ($sortorder == '')
{
$sortorder = 'desc';
}
$sortorder = strtolower($sortorder);
// Count all log entries
$count = $db->query_first("
SELECT COUNT(*) AS `count`
FROM " . TABLE_PREFIX . "thread AS thread
WHERE thread.forumid IN($array)
");
// Make sure all these variables are cool
sanitize_pageresults($count['count'], $pagenumber, $perpage, 100, 40);
switch ($sortfield)
{
case 'username':
$sqlsort = 'thread.postusername';
break;
case 'subject':
$sqlsort = 'thread.title';
break;
case 'type':
$sqlsort = 'thread.iconid';
break;
default:
$sqlsort = 'thread.dateline';
$sortfield = 'age';
}
if ($sortorder != 'asc')
{
$sortorder = 'desc';
$oppositesort = 'asc';
}
else
{ // $sortorder = 'ASC'
$oppositesort = 'desc';
}
$sorturl = 'index.php?' . $vbulletin->session->vars['sessionurl'] . '';
eval('$sortarrow[' . $sortfield . '] = "' . fetch_template('forumdisplay_sortarrow') . '";');
// Default lower and upper limit variables
$limitlower = ($pagenumber - 1) * $perpage + 1;
$limitupper = $pagenumber * $perpage;
if ($limitupper > $count['count'])
{
// Too many for upper limit
$limitupper = $count['count'];
if ($limitlower > $count['count'])
{
// Too many for lower limit
$limitlower = $count['count'] - $perpage;
}
}
if ($limitlower <= 0)
{
// Can't have negative or null lower limit
$limitlower = 1;
}
$threadarray = $vbulletin->db->query_read("
SELECT thread.*, icon.title AS icontitle, icon.iconpath AS iconpath, user.username, user.userid, user.usergroupid, IF(displaygroupid=0, user.usergroupid, displaygroupid) AS displaygroupid
FROM " . TABLE_PREFIX . "thread AS thread
LEFT JOIN " . TABLE_PREFIX . "icon AS icon ON(icon.iconid = thread.iconid)
LEFT JOIN " . TABLE_PREFIX . "user AS user ON (user.username = thread.postusername)
WHERE $typequery
thread.forumid IN($array)
ORDER BY $sqlsort $sortorder $secondarysortsql
LIMIT " . ($limitlower - 1) . ", $perpage ");
while($thread = $vbulletin->db->fetch_array($threadarray))
{
$thread[musername] = fetch_musername($thread);
$thread['lastpostdate'] = timeDiff($thread['dateline']);
// Finally construct the page nav
$pagenav = construct_page_nav($pagenumber, $perpage, $count['count'], 'index.php?' . $vbulletin->session->vars['sessionurl'] . '');
if($count['count'] != 0)
{
$startfrom = $perpage * ($count['count'] - 1);
}
else
{
$startfrom = 1;
}
$images = $db->query("
SELECT img FROM " . TABLE_PREFIX . "post
WHERE threadid = $thread[threadid]
");
while ($image = $db->fetch_array($images))
{
$image_url = $image['img'];
}
eval('$threadbits .= "' . fetch_template('index_threadbit') . '";');
}
$navbits = array();
$navbits[$parent] = 'Thread Index';
$navbits = construct_navbits($navbits);
eval('$navbar = "' . fetch_template('navbar') . '";');
eval('print_output("' . fetch_template('INDEX') . '");');
?>
wolfe
01-18-2008, 09:14 AM
can no one help then i guess ?
Opserty
01-18-2008, 11:44 AM
Place the part where you set $startfrom, outside the loop that displays the thread. Then increment the counter when your inside the while loop.
wolfe
01-18-2008, 12:40 PM
i dont uner stand m8 can u show me with the code i posted ? thx in advance
Opserty
01-18-2008, 01:21 PM
I'm not going to code if for you...
// Set up the counter with the code I posted in post #4
$threadnum = $startfrom;
$db->query....
while($somevar = $db->fetch_array(...
{
// Do your other code here
// Use $threadnum in your template or where ever you want to use the counter
// Increment the counter
$threadnum++;
}
wolfe
01-18-2008, 03:03 PM
sorted m8 but $startfrom = $limitlower - 1; to get the correct number :P
thx again :P
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.