Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2009, 10:01 PM
Zaiaku's Avatar
Zaiaku Zaiaku is offline
 
Join Date: Jul 2007
Location: 3rd Level of Hell
Posts: 502
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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?
Reply With Quote
  #2  
Old 11-24-2009, 10:33 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 11-24-2009, 10:59 PM
Zaiaku's Avatar
Zaiaku Zaiaku is offline
 
Join Date: Jul 2007
Location: 3rd Level of Hell
Posts: 502
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #4  
Old 11-24-2009, 11:29 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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).... 
Reply With Quote
  #5  
Old 11-24-2009, 11:44 PM
Zaiaku's Avatar
Zaiaku Zaiaku is offline
 
Join Date: Jul 2007
Location: 3rd Level of Hell
Posts: 502
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$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
Reply With Quote
  #6  
Old 11-25-2009, 01:22 AM
winstone winstone is offline
 
Join Date: Dec 2006
Posts: 68
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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
Reply With Quote
  #7  
Old 11-25-2009, 02:03 AM
Zaiaku's Avatar
Zaiaku Zaiaku is offline
 
Join Date: Jul 2007
Location: 3rd Level of Hell
Posts: 502
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by winstone View Post
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.
Reply With Quote
  #8  
Old 11-26-2009, 11:08 AM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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'];
    } 
Reply With Quote
  #9  
Old 11-26-2009, 01:37 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by ragtek View Post
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).
Reply With Quote
  #10  
Old 11-26-2009, 01:40 PM
ragtek ragtek is offline
 
Join Date: Mar 2006
Location: austria, croatia
Posts: 1,630
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Lynne View Post
I thought passing the variable would take care of that (see my post 4).
Yea, you're right, my post was referring to his code^^

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


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 05:55 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.04277 seconds
  • Memory Usage 2,272KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (4)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete