PDA

View Full Version : How to Include PHP array variables in the Navbar?


sergey22
Mon 9th Jun '08, 8:20pm
Hi, I'm trying to add my own PHP script that returns an array, so I can use the array variables in the Navbar template, but for some reason I can't get it to work.

1) Short version of the Script looks like this
file is under ./includes/quotes.php


$result = getvariables();
function getvariables () {
$a=1;
$b=2;
return array($a,$b);
}

2) I went to the plugin manager and created a new plugin that looks like this



http://www.vbulletin.com/forum/attachment.php?attachmentid=26612&stc=1&d=1213053369

Question, is there a way to get access to the $result[0] or $result[1] in the Navbar template, and if it is not then what would be an alternative?
I've tried echo results and using $includedphp in the Navbar but it doesn't display anything.

I also have Vbadvanced installed, if that makes any difference, but I don't think it would since navbar does not change.

Thank you very much.

Andy
Mon 9th Jun '08, 9:28pm
I'm no expert, but from what I understand the $includephp that you put in the navbar template will end up being the results from any echo commands in your quotes.php file when the template is run.

What are you trying to do?

sergey22
Tue 10th Jun '08, 12:05am
Thanks Andy, yes something like that would be okay. But for some reason even if I echo $a . " and " . $b, and try to use $includedphp, it would still not show the print result in the Navbar template. Maybe I'm not setting up plugin right.

P.S. Ideally I would like to access variables in the array. so if there is another way it would be great.

sergey22
Tue 10th Jun '08, 12:32am
Okay I got echo with $includedphp to work, it was a syntax error, i had to take out one of the backslashes.

But anyways, if anyone knows how to return array variables to the template, it would be a great help.

Thanks!

sockwater
Tue 10th Jun '08, 12:39am
Do you want to display a random quote in the navbar on each page load? Try this:

includes/quotes.php:

$quotes = array(
'quote one',
'quote two',
'quote three',
);
$randomquote = $quotes[array_rand($quotes)];


in your global_start hook:
include(DIR . '/includes/quotes.php');

Then add $randomquote to your navbar template wherever you want it to show.