reduce queries?
#11
Buddy I am freaking out no matter what I do it juts doesn't work take a look at my code:


function tags_forumdisplay_thread()

{ 
   static $tags_cache = array();
    global $db, $tids, $tags_cache, $thread, $thread_tags;
   
    // get tags for threads on first run
if (!isset($tags_cache)) {
    $tags_cache = array();
    $query = $db->simple_select("tags", "tags, tid", "tid IN (".$tids.")");
    while ($tags = $db->fetch_array($query)) {
        $tags_cache[$tag['tid']] = $tags;
		
		
   
//print_r($tags_cache[$thread['tid']]);
// get thread tags from cache
if (isset($tags_cache[$thread['tid']])) 
{
$thread_tags = $tags_cache[$thread['tid']];
} 
else 
{
$thread_tags = false;
}
}
}
}
$plugins->add_hook("forumdisplay_thread","tags_forumdisplay_thread");

Themplate: forumdisplay_thread: {$thread_tags}


Not showing anything!
Reply
#12
You can't display $tags_cache[$thread['tid']] in a template, it's an array. I guess you need the tags field, so you should retrieve them with this:
$thread_tags = $tags_cache[$thread['tid']]['tags'];
Reply
#13
Thanks buddy but now all thread have the same tags!

But the array seems to be OK

"
Array ( [tags] => Health, Insurance, Health, copayment, coverage, networks ) Array ( [tags] => Using, Debit, card, inplace, Credit, card ) Array ( [tags] => Business, insurance, business, insurance, Business, could ) Array ( [tags] => What, the, sales, tax, the, United, States, USA ) Array ( [tags] => Best, health, insurance, companies, health, companies ) Array ( [tags] => Make, money, from, home, spending, decent ) Array ( [tags] => How, make, Million, one, year ) Array ( [tags] => How, get, into, freelance, marketing ) Array ( [tags] => Custom, code, modefication, will, pay ) Array ( [tags] => The, Blue, Crown, Capital, Management, Specialists, Mortgage, Refinancing ) Array ( [tags] => What, general, Marketing, means, general, means ) Array ( [tags] => How, much, does, copyrights, cost ) Array ( [tags] => Black, Friday, What, Does, Mean ) Array ( [tags] => World, Wealthiest, People, Top, Billionaires, List ) Array ( [tags] => favorite, CPA, network, apart, money, networks ) Array ( [tags] => What, are, best, marketing, strategies, tips, and, tricks ) Array ( [tags] => What, the, most, profitable, businesses, start ) Array ( [tags] => How, make, money, from, home ) Array ( [tags] => Selling, used, cars, business, dealers, about ) Array ( [tags] => How, become, rich, trading, Forex ) Array ( [tags] => Digital, Marketing, digital, marketing, please, share ) Array ( [tags] => What, quotLink, Wheelquot, black, hat, technique )"
Reply
#14
A typo in my previous code - replace
$tags_cache[$tag['tid']] = $tags;
with
$tags_cache[$tags['tid']] = $tags;

It wasn't saving the data correctly.
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#15
guys you are awesome!

Still shows the same tags for all thread!


function tags_forumdisplay_thread()

{ 
   //static $tags_cache = array();
    global $db, $tids, $tags_cache, $thread, $thread_tags;
   
    // get tags for threads on first run
if (!isset($tags_cache)) {
    $tags_cache = array();
    $query = $db->simple_select("tags", "tags, tid", "tid IN (".$tids.")");
    while ($tags = $db->fetch_array($query)) {
        $tags_cache[$tags['tid']] = $tags;
		
// get thread tags from cache
if (isset($tags_cache[$thread['tid']])) 
{
$thread_tags = $tags_cache[$thread['tid']]['tags'];
} 
else 
{
$thread_tags = false;
}
}
}
}
Reply
#16
The brackets are out of order. Maintain correct indentation to avoid confusion.

function tags_forumdisplay_thread()
{

    //static $tags_cache = array();
    global $db, $tids, $tags_cache, $thread, $thread_tags;
   
    // get tags for threads on first run
    if (!isset($tags_cache)) {
        $tags_cache = array();
        $query = $db->simple_select("tags", "tags, tid", "tid IN (".$tids.")");
        while ($tags = $db->fetch_array($query)) {
            $tags_cache[$tags['tid']] = $tags;
        }
    }

    // get thread tags from cache
    if (isset($tags_cache[$thread['tid']]))
    {
        $thread_tags = $tags_cache[$thread['tid']]['tags'];
    } 
    else 
    {
        $thread_tags = false;
    }

}
devilshakerz.com/pgp (DF3A 34D9 A627 42E5 BC6A 6750 1F2F B8AA 28FF E1BC) ▪ keybase.io/devilshakerz
Reply
#17
static $tags_cache = array(); 
//...
if (!isset($tags_cache)) {

Quote:I am putting into it more than enough effort

Sure.
Reply
#18
Thanks very much guys specially @Devilshakerz works awesome generates queries dropped from 78 to 26
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)