The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
||||
|
||||
variables in php files
I'm having a slight issue with a script I'm making. And I'm wondering if something very simple I'm missing. Right now the code is hard coded into the php file, and so is the settings. The problem is with a vairable. It's pulling a list of the last X members from the database.
The problem is that when using a variable ex: $grabbedmembers It doesn't work in the SQL call. Variable is empty even though near the top of the php file I have $grabbedmembers = 5 But if I just replace the variable with the number in the SQL call it works. Do all variables in php file need to be register before working? Or just variables that will be used in templates? |
#2
|
||||
|
||||
Post your code and we'd be able to help better. Variables need to be registered for use in templates not in the php files.
|
#3
|
||||
|
||||
Here;s the one for the last few threads:
Code:
$Zforum = 5; private function fetch_lastids() { $lastx = $this->registry->db->query_first(" SELECT COUNT(`threadid`) AS `lastx` FROM " . TABLE_PREFIX . "thread AS thread WHERE thread.forumid IN (0,". $Zforum. ") AND thread.visible = 1 "); $this->threadscount = $lastx['lastx']; } |
#4
|
||||
|
||||
Have you tried passing the variable to the function.
PHP Code:
|
#5
|
||||
|
||||
$a_var remains empty. For some reason I can't get it to store any value what so ever. Although works fine in vb3.8. Thre must be something new in vb4 causing the problem
|
#6
|
|||
|
|||
just before your mysql query, put:
PHP Code:
if the result was correct, some code in between is messing up with this variable |
#7
|
||||
|
||||
Quote:
OK I figured it out. Wow programming in vb4 did add something new to the variables. I figured it out. It was just a delaration inside the funtion. Once added it worked flawlessly. Thx everyone for helping. |
#8
|
|||
|
|||
In your first code, $Zforum was not in the scope!
You can't use variables inside a function which are declared outsite withouth an global PHP Code:
|
#9
|
||||
|
||||
I thought passing the variable would take care of that (see my post 4).
|
#10
|
|||
|
|||
Quote:
Youre code will also work, i showed him just another possible code. |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|