PDA

View Full Version : Using Array in Template Problem


BamaStangGuy
10-19-2007, 06:12 AM
I am trying to get this to work right.

<if condition="$thread['forumid'] == 32"><div style="margin-top: 7px;"><a href="http://www.exposethemusic.com/forums/t$lyrics[threadid]/">$lyrics[title] Lyrics</a></div></if>

if ($foruminfo['forumid'] == 32)
{
$lyrics = '';
$lyrics = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "thread WHERE forumid = 34 AND title = '" . $threadinfo['title'] . "'");
}

Using showthread_start query

If I use a print_r on $lyrics it spits out the array at the top of the page. So I know the query works.

print_r($lyrics['title']); spits out the correct title to.

What isn't working is when I use the variable in the template. It just shows up blank where the variable output is suppose to be.

Any idea why?

Guest190829
10-19-2007, 07:26 AM
What template are you using it in? And you should have to query the thread table, as this is already done and the info is put in $thread array.

BamaStangGuy
10-19-2007, 08:47 AM
postbit

I'm not sure how I would compare the post title of one forum with the post title of another one to make sure they are the same based on the thread you are in without a query. It very well could be possible but I have no idea how.

--------------- Added 1192824968 at 1192824968 ---------------

Anyone else have any idea? Like I said, the query works fine and the variable has the array in it but it won't work when used in a template :(

BamaStangGuy
10-21-2007, 07:11 AM
if ($foruminfo['forumid'] == 32)
{
$lyrics = '';
$lyrics = $vbulletin->db->query_first_slave("
SELECT *
FROM " . TABLE_PREFIX . "thread
WHERE forumid = 34 AND title = '" . mysql_escape_string($threadinfo['title']) . "' LIMIT 1
");
}

I am guessing the variable scope is preventing me from using $lyrics within the postbit template? I have tried adding global $lyrics; to the above plugin and add it as a seperate plugin in global start but it still won't work.

I've tried $GLOBALS[lyrics] in the template but no luck either.

What am I missing here? All I want to do is use $lyrics within postbit

Guest190829
10-21-2007, 07:31 AM
I am not really sure what you are doing. The thread you are pulling is different then the one you that the post belongs too? It seems you like you have some issues with database normalization, if that is the case.

I am just trying to get this efficient as possible for you.

Adrian Schneider
10-21-2007, 07:55 AM
Add a plugin to postbit_display_complete global $lyrics;

The postbit template is not evaluated in global scope.

BamaStangGuy
10-21-2007, 05:15 PM
I am not really sure what you are doing. The thread you are pulling is different then the one you that the post belongs too? It seems you like you have some issues with database normalization, if that is the case.

I am just trying to get this efficient as possible for you.

http://www.exposethemusic.com/forums/t648/
http://www.exposethemusic.com/forums/t644/

Those two threads are the same. What I am trying to do is if you are in f32 I am taking the thread title of the thread you are in and searching f34 to see if the exact same thread exists. If it does then I want to link to that thread.

Add a plugin to postbit_display_complete global $lyrics;

The postbit template is not evaluated in global scope.
Giving this a shot

Thanks this worked :)