type=="postgresql"){
$limit="";
$q->query($DB, "set QUERY_LIMIT TO '$nDisplay'");
}
else{
$limit=" limit $nDisplay";
}
if($thread==0 || $action==0){
$sSQL = "Select max(thread) as thread from $TableName";
$q->query($DB, $sSQL);
if($q->numrows()>1){
$maxthread=$q->field("thread", 0);
}
else{
$maxthread=0;
}
$cutoff_thread=$maxthread-$cutoff;
if($$phcollapse==0){
$sSQL = "Select thread from $TableName where thread > $cutoff_thread order by thread desc".$limit;
}
else{
$sSQL = "Select thread, count(*) as tcount, max(datestamp) as latest, max(id) as maxid from $TableName where thread > $cutoff_thread group by thread order by thread desc".$limit;
echo "\n";
}
}
else{
if($action==1){
$cutoff_thread=$thread+$cutoff;
$sSQL = "Select thread from $TableName where thread < $cutoff_thread and thread > $thread order by thread".$limit;
$q=new query($DB, $sSQL);
if($rows=$q->numrows()){
$thread = $q->field("thread",$rows-1);
}
$thread=$thread+1;
}
$cutoff_thread=$thread-$cutoff;
if($$phcollapse==0){
$sSQL = "Select thread from $TableName where thread < $thread and thread > $cutoff_thread order by thread desc".$limit;
}
else{
$sSQL = "Select thread, count(*) as tcount, max(datestamp) as latest, max(id) as maxid from $TableName where thread < $thread and thread > $cutoff_thread group by thread order by thread desc".$limit;
echo "\n";
}
}
$thread_list = new query($DB, $sSQL);
if($DB->type=="postgresql"){
$q->query($DB, "set QUERY_LIMIT TO '0'");
}
$rows = $thread_list->numrows();
if($rows==0 && $action!=0){
Header("Location: $list_page.$ext?num=$num$GetVars");
exit();
}
echo "\n";
if($$phcollapse==0){
$sSQL = "Select id,parent,thread,subject,author,datestamp from $TableName where thread<=$max and thread>=$min order by thread desc, id asc";
}
else{
$sSQL = "Select id,parent,thread,subject,author,datestamp from $TableName where thread<=$max and thread>=$min and thread=id order by thread desc";
}
echo "\n";
$msg_list = new query($DB, $sSQL);
if(file_exists("header_$TableName.inc")){
include "./header_$TableName.inc";
}
else{
include "./header.inc";
}
if($$phcollapse==0){
$collapse_link = "".$lCollapseThreads."";
}
else{
$collapse_link = "".$lViewThreads."";
}
if(count($forums)>1){
$nav = "
";
}
else{
$nav = "";
}
?>