vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   variables in php files (https://vborg.vbsupport.ru/showthread.php?t=228811)

Zaiaku 11-24-2009 10:01 PM

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?

Lynne 11-24-2009 10:33 PM

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.

Zaiaku 11-24-2009 10:59 PM

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'];
    }

Now where it says $Zforum in the SQL quiery. If I just replace that with the number 5 then it works.

Lynne 11-24-2009 11:29 PM

Have you tried passing the variable to the function.

PHP Code:

private function fetch_lastids($a_var)
    {
        
$lastx $this->registry->db->query_first("
        SELECT COUNT(`threadid`) AS `lastx`
        FROM " 
TABLE_PREFIX "thread AS thread
        WHERE thread.forumid IN (0,"
$a_var ")
        AND thread.visible = 1
        "
);
        
$this->threadscount $lastx['lastx'];
    }

..... 
fetch_lastids($Zforum).... 


Zaiaku 11-24-2009 11:44 PM

$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

winstone 11-25-2009 01:22 AM

just before your mysql query, put:
PHP Code:

var_dump($a_var);
exit; 

if result was null, put the code above just after the code "$Zforum = 5;"
if the result was correct, some code in between is messing up with this variable

Zaiaku 11-25-2009 02:03 AM

Quote:

Originally Posted by winstone (Post 1920497)
just before your mysql query, put:
PHP Code:

var_dump($a_var);
exit; 

if result was null, put the code above just after the code "$Zforum = 5;"
if the result was correct, some code in between is messing up with this variable

OK it did return the right number so now I know its something in the coding that is clearing all stored variables. At least now I'm cutting down the problem.

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.

ragtek 11-26-2009 11:08 AM

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:

$Zforum 5;

    private function 
fetch_lastids()
    {
global 
$Tforum;
        
$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'];
    } 


Lynne 11-26-2009 01:37 PM

Quote:

Originally Posted by ragtek (Post 1921127)
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 ;)

I thought passing the variable would take care of that (see my post 4). :confused:

ragtek 11-26-2009 01:40 PM

Quote:

Originally Posted by Lynne (Post 1921189)
I thought passing the variable would take care of that (see my post 4). :confused:

Yea, you're right, my post was referring to his code^^

Youre code will also work, i showed him just another possible code.


All times are GMT. The time now is 08:42 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.01034 seconds
  • Memory Usage 1,747KB
  • 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
  • (1)bbcode_code_printable
  • (4)bbcode_php_printable
  • (3)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete