PDA

View Full Version : displaying a variable from the database


ohadpartuck
04-24-2012, 02:44 PM
Hi,
I have a php script that runs on a page that is called chat.php.
It counts the current active users and save that to the database.

I want to display that number on the navigation bar in next to the chat link.
How do I do that?
I have read this (https://vborg.vbsupport.ru/showthread.php?t=257589) article that saves an adittional field and displays it but that was when an article loads.
how do I make it for the navbar loading?:)

kh99
04-24-2012, 03:28 PM
You want to display it on the navbar on all pages (not just your chat page)? Then you need to create a plugin that queries the database for that value, then registers it to the navbar template. Then you can edit the navbar template and insert that value where you want it. Something like:

$chatters = $vbulletin->db->query_first("SELECT chatters FROM some_table");
vB_Template::preRegister('navbar', array('chatters' => $chatters['chatters']));


then in the navabr template

{vb:raw chatters}


The hook choice is a little tricky (or maybe someone else knows better), but you'd ideally not want to add the query unless it's needed, but since the navbar is rendered in a bunch of separate scripts there doesn't seem to be any way to know for sure when it's needed. In any case global_setup_complete should work.

Boofo
04-24-2012, 03:53 PM
The preRegister line should be this:

vB_Template::preRegister('navbar', array('chatters' => $chatters));

ohadpartuck
04-25-2012, 09:07 AM
thanks boofo, but kh99 was right because the sql query returns an array.

It works partially. I can disaply the chatters on the page, but not where I want it.

Let's say I wnat to add a new link to the chat page in the navigation bar called "Chat" (the one I have now is via DBTech - vBNavTabs so that cant work (I've tried)).

I've tried to add in various locations in the 'navbar' Template :
<li><a href="mycahatlink" class="navtab">My chat Tab</a></li>

But it's not adding!!! dammit!

please help me with this one..

Boofo
04-25-2012, 09:22 AM
Okay, I see how he did it. By doing it his way, you can skip a few steps in setting it up.

ohadpartuck
04-25-2012, 10:13 AM
does anyone know a good solution for the other problem that I wrote?

Boofo
04-25-2012, 10:30 AM
Lynne did an article on adding Tabs a while back. You might want to check it out in the Articles area.