vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   latest threads in forumdisplay.php? (https://vborg.vbsupport.ru/showthread.php?t=38355)

TECK 05-07-2002 05:36 AM

latest threads in forumdisplay.php?
 
i want to show the latest 10 threads, pulled from all forums in forumdisplay.php. i have this code:
Code:

// get latest threads
$forums=$DB_site->query("SELECT * FROM forum WHERE active=1");
$forumids='forumid IN (0';
while ($forum=$DB_site->fetch_array($forums)) {
  $getperms=getpermissions($forum['forumid']);
  if ($getperms[canview]) {
    $forumids .= "," . $forum['forumid'];
  }
}
$forumids.=')';

unset($forum);

$getthreads=$DB_site->query("SELECT * FROM thread WHERE $forumids AND visible=1 ORDER BY lastpost DESC LIMIT 10");
while ($lastthread=$DB_site->fetch_array($getthreads)) {
  $threadid=$lastthread[threadid];
  $titleextra='';
  if (strlen($lastthread[title])>32) {
    $titleextra="...";
  }
  $threadtitle=substr($lastthread[title], 0, 29);
}

eval("\$lastthreadbits .= \"".gettemplate('home_threadbits')."\";");

everything is working fine... hmm the problem is that it's making me jump from 21 to 40!!!! queries. is there a way to cache somehow those pesky queries? thanks for your help.

E 05-07-2002 10:17 AM

i dont see 19 queries... only 4

Admin 05-07-2002 11:07 AM

getpermissions() = lots of queries, and shouldn't be used in a loop I believe.

TECK 05-07-2002 04:33 PM

is the perms that add a query for each thread... you have an idea how it would be the code to pull it out of the loop?
i honestly dont know. as you know firefly, i look at the VB script code and try to make something similar. thare are certain things i do not manage yet. let me know if you could write the loop part here for me. thanks.

Scott MacVicar 05-07-2002 04:49 PM

try this

PHP Code:

//perms
$fperm=$DB_site->query("SELECT canview,forumid FROM forumpermission WHERE usergroupid='$bbuserinfo[usergroupid]'");
while(
$fperms $DB_site->fetch_array($fperm)) {
  
$perms["$fperms[forumid]"] = $fperms;
}
$DB_site->free_result($fperm);
unset(
$fperms);
//forums
$forum=$DB_site->query("SELECT forumid FROM forum");
while (
$forums=$DB_site->fetch_array($forum)) {
  if(
$fperms["$forums[forumid]"]["canview"] == 1) {
    
$forumperms[]=$forums["forumid"];
  }
  else {
    
$forumperms[]=$forums["forumid"];
  }
}
$DB_site->free_result($forum);
unset(
$forums);

if(!empty(
$forumperms)) {
  
$forumperms='AND forumid='.implode(' OR forumid=',$forumperms);
}
$getthreads=$DB_site->query("SELECT * FROM thread WHERE open='1' AND open<>10 $forumperms ORDER BY lastpost DESC LIMIT 10"); 

you should add open<>10 in the query as that is moved threads which you don't want, as it will pick up the moved thread plus the redirect left in the old forum.

TECK 05-07-2002 07:05 PM

thanks alot scott.

now, can i pm you about an issue that i develloped with a different file? i cannot post the contents of the file because it contains 60% VB script code. i already asked firefly for help. just leting you know that is nothing related to this thread here. i ask this because maybe firefly is busy and i dont want to pm every single one of you every day.

if any of you is willing to take a look at the file (firefly, ppn or zzed), please post an answer here and i will attach the file in your pm. is about a misterious query that is added every time i refresh the page. originally it starts with 21 queries on the page, when i login. as soon as i refresh, it adds a new query, for a total of 22. i cant seem to find where it must be unset the forgotten variable, in that file.

one more time, thanks.

KuraFire 05-07-2002 07:48 PM

Doesn't work at all for me, PPN.

Using your code exactly except for the last query line (mine is: $threadsql = $DB_site->query("SELECT lastposter, threadid, title, replycount FROM thread WHERE open<>10 $forumperms ORDER BY lastpost DESC LIMIT 69"); ) this just didn't work. I made a thread in my admin&mods forum, but a normal member still sees the thread listed while viewing my newsportal. :(

TECK 05-07-2002 08:03 PM

Quote:

Originally posted by nakkid
if any of you is willing to take a look at the file (firefly, ppn or zzed), please post an answer here and i will attach the file in your pm. is about a misterious query that is added every time i refresh the page. originally it starts with 21 queries on the page, when i login. as soon as i refresh, it adds a new query, for a total of 22.
i found it! :) thanks alot guys.

Scott MacVicar 05-07-2002 08:19 PM

does your newsportal include global.php and load the $bbuserinfo array?

KuraFire 05-07-2002 08:51 PM

it includes global.php but I have nothing added myself pertaining to a $bbuserinfo array or anything like that.


All times are GMT. The time now is 05:02 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01882 seconds
  • Memory Usage 1,745KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete