Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 10-24-2005, 12:13 AM
Osterling Osterling is offline
 
Join Date: Jan 2004
Posts: 381
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default variable scope

Well I running into a problem and I could use some advice. Let me explain how I'm setting up my site and what exactly it is that is giving me trouble.

I have a file which includes only 4 php include statements. One for the the header, nav, body and footer. Each contain part of the style and when all files are together it creates my style. Simple.

Well my body.php page is where my text is. I use an include statement to bring in file it is suppose to retrieve, and within that file is a variable which contains a value "page title".

I took the variable $titleofpage and used as an argument in my function I created.

That variable named "titleofpage" scope isn't working in my navigation where I call a function that I created on index.php file. I call the function on the nav.php file but the page title doesn't show. I am thinking it has something to do with my variable scope.

Any help would be appreciate, and I hope I made myself clear.
Reply With Quote
  #2  
Old 10-24-2005, 12:19 AM
Guest190829
Guest
 
Posts: n/a
Default

try

PHP Code:
die("$titleofpage"
on different parts of the scripts, to see where the exact problem is.
Reply With Quote
  #3  
Old 10-24-2005, 12:44 AM
Osterling Osterling is offline
 
Join Date: Jan 2004
Posts: 381
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

alright. i defined the variable in a html file, from there that file is called on from the body.php file in which it will show the variable. however when i use the variable in my nav.php file it won't show its value, and both body.php and nav.php are put together from include statements coming from the index.php file if that doesn't make sense let me know.

but how come it works fine for the body.php file but not nav.php?
Reply With Quote
  #4  
Old 10-24-2005, 01:19 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

you mentioned you're using functions?

If so use this as an example..

PHP Code:
<?php
$titleofpage 
"title of page";

function 
somefunction()
{
  global 
$titleofpage;

   echo 
"$titleofpage";
}
?>
Reply With Quote
  #5  
Old 10-24-2005, 02:16 AM
Osterling Osterling is offline
 
Join Date: Jan 2004
Posts: 381
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

here is a little outline of my php pages and to help give a better idea of what it is i am needing help.

index.php (contains all include statements to execute the files below in that order)
- header.php
- nav.php (when I try to call the pagetitle function here to run it, it says undefined)
- body.php (if I call the function here it will execute perfectly)
>> articles(inserted through the php include statement > article 1 (which contains the function pagetitle)
- footer.php

how can i get it so that the function i created in the article 1.html file will run and execute in nav.php

any help is always appericated.
Reply With Quote
  #6  
Old 10-24-2005, 02:26 AM
harmor19 harmor19 is offline
 
Join Date: Apr 2005
Posts: 1,324
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I'm cunfused...
how can you make a function in an html file (article 1.html)?

can you make small mock ups of each script?
I'll have to test them out because I can't solve it.

sorry.
Reply With Quote
  #7  
Old 10-24-2005, 02:33 AM
Osterling Osterling is offline
 
Join Date: Jan 2004
Posts: 381
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i have it inserted in <?php ?> tags. the function runs in body.php but not in nav.php but i've changed it to .php now.

it maybe a sloppy way to code, i'm just beginning my coding experince with php :-/

if you want i can post each page of code so you can get a good idea, if that is what your asking for.

index.php
PHP Code:
<?php
include ("header.php");
include (
"articles/top.php");
include (
"articles/body.php");
include (
"footer.php");
?>
nav.php
PHP Code:

                <TD COLSPAN=12>
            <IMG SRC="images/layout_02.gif" WIDTH=605 HEIGHT=12 ALT=""></TD>
    </TR>
    <TR>
        <TD COLSPAN=3>
            <IMG SRC="images/layout_03.gif" WIDTH=48 HEIGHT=23 ALT=""></TD>
        <TD>
            <IMG SRC="images/layout_04.gif" WIDTH=165 HEIGHT=23 ALT=""></TD>
        <TD>
            <IMG SRC="images/layout_05.gif" WIDTH=12 HEIGHT=23 ALT=""></TD>
        <TD COLSPAN=3>
            <IMG SRC="images/layout_06.gif" WIDTH=117 HEIGHT=23 ALT=""></TD>
        <TD COLSPAN=4>
            <IMG SRC="images/layout_07.gif" WIDTH=263 HEIGHT=23 ALT=""></TD>
    </TR>
    <TR>
        <TD COLSPAN=3>
            <IMG SRC="images/layout_08.gif" WIDTH=48 HEIGHT=48 ALT=""></TD>
        <TD COLSPAN=4>
            <IMG SRC="images/layout_09.gif" WIDTH=283 HEIGHT=48 ALT=""></TD>
        <TD COLSPAN=2>
            <IMG SRC="images/layout_10.gif" WIDTH=177 HEIGHT=48 ALT=""></TD>
        <TD COLSPAN=3>
            <IMG SRC="images/layout_11.gif" WIDTH=97 HEIGHT=48 ALT=""></TD>
    </TR>
    <TR>
        <TD COLSPAN=2>
            <IMG SRC="images/layout_12.gif" WIDTH=36 HEIGHT=47 ALT=""></TD>
        <TD COLSPAN=4 align=left>
                <?php echo pagetitle(); ?></td>
        <td colspan=4 align=right>Table Row 2</td>

        <TD COLSPAN=2>
            <IMG SRC="images/layout_14.gif" WIDTH=86 HEIGHT=47 ALT=""></TD>
    </TR>
    <TR>
        <TD COLSPAN=12>
            <IMG SRC="images/layout_15.gif" WIDTH=605 HEIGHT=23 ALT=""></TD></TR><tr>
body.php
PHP Code:
<td colspan=3 background="images/layout_16.gif">
    <img src="images/layout_16.gif" width=48 height=12 alt="">
</td>
<td name=body colspan=7 rowspan=2 bgcolor="#0000FF" valign="top" style="padding-left: 4; padding-right: 4; padding-top: 4; padding-bottom: 4">
<?php

if (!$_GET['article'])
{
     include (
'article/home.php');
}
else
{
     
$pagetitle=$_GET['article'];
     
     switch(
$pagetitle)
     {
     case 
"home":
     include (
'article/home.php');
     break;
     
     case 
"theaccident":
     include (
'article/theaccident.php');
     break;
     
     
 default: }
}
?>
</td>
<TD COLSPAN=2 background="images/layout_18.gif">
            <IMG SRC="images/layout_18.gif" WIDTH=86 HEIGHT=12 ALT=""></TD>
    </TR>
    <TR>
        <TD COLSPAN=3 background="images/layout_19.gif">
            <IMG SRC="images/layout_19.gif" WIDTH=48 HEIGHT=236 ALT=""></TD>
article.php
PHP Code:
<?php
$titleofpage 
"The Accident";

function 
pagetitle()
{
  global 
$titleofpage;

  echo 
"Where You're At: <br>&nbsp;&nbsp;&nbsp;&nbsp;<strong>Index > The Guide >&nbsp;".$titleofpage."</strong>";
}
?>
<p class="MsoNormal" style="text-indent:.5in;line-height:150%">
I think we all have a moment when we see and acknowledge that we are
            indeed exposed to the real possibility of something extremely bad
            happening to us. That if we don?t start considering the consequences
            to our actions, we may regret what happens to us as a ripple affect
            from them. For me, It was never like I thought I was immune to the
            bad things, I just never thought it would happen to me.&nbsp; It was too
            unlikely in my eyes, so when the truck swerved I never could have
            guessed what would be coming next.&nbsp; I have always learned best by
            experience, and I guess this lesson was no different. </p>
            <p class="MsoNormal" style="text-indent:.5in;line-height:150%">It
            was Friday, and school had just let out. Instead of taking a ride
            from Brain I decided to get a ride from Ben.&nbsp; In the truck there was
            Ben, Matt, Chad and me.&nbsp; Ben and Matt were sitting in the front,
            while Chad and I sat in the back. We pulled out onto Fifth Street
            and I looked out my window. I remember seeing kids and then I felt a
            jerk.&nbsp; I slide to the middle of the back seat, and began to look
            through the windshield to see what was going on.&nbsp; It had been a van
            that pulled out in front of us that had caused Ben to swerve.&nbsp; I
            remember thinking to myself; I hope I make it out alright and then
            time slowed down dramatically.&nbsp; Looking through the windshield I
            could see the kids ahead, and before I had time to think ?what?s
            going to happen? I felt it. It felt as if we were hitting trees and
            running them over, but instead of trees they were kids. Then I felt
            the kids under the truck as it rolled over on them, and I remember
            hearing the screams from the people witnessing it.&nbsp; The sound of the
            screaming made me think back to Columbine, so when the truck finally
            stopped I was terrified of what just happened.&nbsp; I knew it was bad,
            if not from what I felt, what I saw but just from what I heard.</p>
            <p class="MsoNormal" style="text-indent:.5in;line-height:150%">It
            was then I realized how fast things can change, and without your
            control.&nbsp; How important it is to understand your actions may affect
            someone else and how unfair that might be to them.&nbsp; I?ve learned
            that I am mortal, that bad things can happen to me and that I need
            to be aware of the dangers and do my best to prevent them.&nbsp;
Reply With Quote
Reply

Thread Tools
Display Modes

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 01:58 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05424 seconds
  • Memory Usage 2,246KB
  • Queries Executed 11 (?)
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
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (7)post_thanks_box
  • (7)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (7)post_thanks_postbit_info
  • (7)postbit
  • (6)postbit_onlinestatus
  • (7)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_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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete