vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Getting forum ID through php? (https://vborg.vbsupport.ru/showthread.php?t=207019)

ButtKrust 03-01-2009 05:23 PM

Getting forum ID through php?
 
I was wondering how you go about getting the forum ID put into a variable or even just echo'd through PHP. Does it have anything to do with using the $_REQUEST['forumid']? Could someone give me a short code sample of how to echo a forum ID through PHP or point me to a topic that does? Just using "echo $_REQUEST['forumid']" doesn't work. I've tried searching but I can't find anything specific to what i need. thanks.

Lynne 03-01-2009 05:30 PM

It depends on where you are using the variable. Most people use it in a template and you can see all the places it is used in a template by doing a Search In Templates for "forumid" (no quotes). Note that the exact name of the variable is different depending on what template it is used in.

ButtKrust 03-01-2009 05:32 PM

I'm actually using it in a .php file which is displayed by a vbadvanced module. Would i need to connect to my database and pull the forum id from there instead? $foruminfo[forumid] isn't working.

--------------- Added [DATE]1235936765[/DATE] at [TIME]1235936765[/TIME] ---------------

Actually when i put require_once('./global.php'); at the top of the page, i can get "echo $_REQUEST['forumid'];" to display '0', but not '5' which is the actualy forum id. Any ideas?

Lynne 03-01-2009 05:48 PM

Have you tried just $forumid? And, what are you getting the forumid *of*? That is the clue to actually getting it because you need to pull it from whatever query you are using. Unless you are actually in a forum, you won't have a forumid of anything unless you query for it.

ButtKrust 03-01-2009 05:55 PM

$forumid didn't work. I'm trying to get the forum ID of the forum that contains the module with this php file. I tried having it connect to the database and use "SELECT forumid FROM forum" but this output "Recource id #3" instead of '5', which again is the actual forum id that contains the module. I think i'm getting myself way off track...

Mr-Moo 03-01-2009 06:15 PM

Would you mind clarifying your entire objective a little more? After reading this Lynne has provided a solution, but I don't quite understand what you are looking for.

// Edit //
Is the forumID static or dynamic? What are the conditions?

ButtKrust 03-01-2009 06:21 PM

Alright I am using vbadvanced. I have a module of my forum which outputs a .php file. In this php file, i would like to find out the forum id in order that i might display something specific to each forum in that module. Just to keep things simple, though, i would like to echo or assign to a variable the forum ID that contains this module and php file. Basically when the page is loaded and the php file is loaded i want it to check the forum id so that i can set specific functions based on that forum id.

Mr-Moo 03-01-2009 06:37 PM

If I am not mistaken you are looking for something that does the following:

-When the forum page loads it checks the ForumID.
-If the forum ID matches a specific command, it outputs X item.

If this is what you are looking for, this is just a simple if else function.

PHP Code:

<?php
if ($forumid 1)
{
echo 
"Your desired output";
}
elseif (
$forumid 2)
{
echo 
"Desired output for 2";
}
else
{
echo 
"Desired output for FALSE";
}
?>


ButtKrust 03-01-2009 06:41 PM

$forumid decided to start working, i guess i missed it earlier. This is exactly what i needed, thank you both very much and i'm very sorry for misunderstanding so much.

Mr-Moo 03-01-2009 06:42 PM

No problem, was my code of any assistance, or were you simply in need of the $forumid portion?

ButtKrust 03-01-2009 06:46 PM

It was your code that made me realize that $forumid was in fact working in that php file ;-)

--------------- Added [DATE]1235944263[/DATE] at [TIME]1235944263[/TIME] ---------------

I've actually got another problem now. When i use the part of your code like if(forumid=5) then do this, it works fine. AFTER this part of the code, then i can get "echo $forumid" to display something. However, If i simply try to use "echo $forumdisplay" WITHOUT any other code (such as the if statement), it doesn't display anything or work. Any reason why this happens? It seems that if($forumid = 5) is assigning the value of 5 to $forumid, rather than giving me the actual forumid. Since if i view this on a page where forum id is actually 6, it still displays 5 because that is what $forumid was assigned. I guess i'm back to my starting problem of pulling the actual forum id. I was fooled earlier.

Lynne 03-01-2009 07:59 PM

I don't understand the full problem (probably partly because I am totally unfamiliar with vbadvanced), but you are using php and thus the condition should be if($forumid == '1') - a double equal, not a single one.

ButtKrust 03-01-2009 08:03 PM

I'm just back at stage one it seems, i need to be able to recognize the current forum id with some sort of function. To keep it very simple, how would i output the current forum id with ECHO? In such a way that when i am at ForumA with the ID of 5, it will echo '5'. But when i go on over to forumB with ID of 6, it will echo '6'. This is what i'm really getting at.

Mr-Moo 03-01-2009 08:21 PM

Should be as simple as:

PHP Code:

echo $forumid

And thank you for that correction Lynne, you are correct. It was an operation being compared.

ButtKrust 03-01-2009 08:23 PM

Quote:

Originally Posted by Mr-Moo (Post 1757877)
Should be as simple as:

PHP Code:

echo $forumid

And thank you for that correction Lynne, you are correct. It was an operation being compared.

Is there a specific outside php file i need to "Include" at the top of my current php file in order for $forumid to actually work properly?

Mr-Moo 03-01-2009 08:25 PM

No, but then again I do not know where you are placing this at. What file are you editing? The global.php may need to be included.

ButtKrust 03-01-2009 08:26 PM

Quote:

Originally Posted by Mr-Moo (Post 1757881)
No, but then again I do not know where you are placing this at. What file are you editing? The global.php may need to be included.

in a separate php file all by itself. I guess that's my problem, i'll try including the global.

--------------- Added [DATE]1235946568[/DATE] at [TIME]1235946568[/TIME] ---------------

Including global.php didn't work.. it must be that i have to include a file. I'll try to find the right one.

--------------- Added [DATE]1235948936[/DATE] at [TIME]1235948936[/TIME] ---------------

If i include global.php and then use "Echo $foruminfo", it echoes "array" and if i use "Echo $foruminfo[forumid]" nothing comes out. I think i'm on to something by getting "array" to display, is there a way i can go about analyzing the array and extracting the forum id from it?

Dismounted 03-02-2009 05:02 AM

PHP Code:

print_r($foruminfo); 


ButtKrust 03-02-2009 05:11 AM

The only two things i've managed to have output anything while having global.php included are "Echo $foruminfo" which outputs the word "Array" and what you just posted, print_r($foruminfo) which outputs "Array ( )" So apparently it knows that $foruminfo is an array... how do i go about grabbing the forumid part of that array? No form of "$foruminfo['forumid']" seems to work. In fact when i use that, it outputs nothing rather than even the word array.

Keep in mind this is a separate php file so i know there's got to be some trick to grabbing the forum id from the separate php file, but i just can't figure out how. Am i missing some include files that need to be included?

Dismounted 03-02-2009 05:18 AM

Using the code I posted will allow you to see what is contained inside the array...


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.01495 seconds
  • Memory Usage 1,765KB
  • 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
  • (4)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (20)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete