Jump to content

Recommended Posts

Hello:

 

I have this code in an included file:

myNav.php

function spLeftMenu() {
$spLeftMenu =
"
<p>
<div id=\"myLeftNavPaper\">
<img src=\"images/sidePaperTop.png\" alt=\"\" />

<div id=\"myLeftNavPaper2\">

echo \". $mySideBarPageData .\"

</div>

<img src=\"images/sidePaperBottom.png\" alt=\"\" />
</div>

</p>

";
return $spLeftMenu;
}

 

I can not get:

echo \". $mySideBarPageData .\"

 

To display the results on this page:

Page.php

<html>
...

<?php echo spLeftMenu(); ?>		

...
</html>

 

 

What am I missing ??

why are you echoing like that?

<?php
function spLeftMenu() {
$spLeftMenu =
"
<p>
<div id=\"myLeftNavPaper\">
<img src=\"images/sidePaperTop.png\" alt=\"\" />

<div id=\"myLeftNavPaper2\">{$mySideBarPageData}</div>

<img src=\"images/sidePaperBottom.png\" alt=\"\" />
</div>

</p>

";
return $spLeftMenu;
} ?>

at least. but i dont really understand the why you are doing it that way..

You should read up on variable scope. Functions have their own variable scope meaning variables defined outside of them cannot be used within them. When using variables with functions you should be passing them as arguments. eg

 

function myFunc($myVar)
{
    echo $myVar;
}

$myVar = 'something';
myFunc($myVar); // pass $myVar to the function

Not sure I understand ...

 

This:

<p>

<div id=\"myLeftNavPaper\">
<img src=\"images/sidePaperTop.png\" alt=\"\" />

<div id=\"myLeftNavPaper2\">


echo ". ('$mySideBarPageData;') ."

</div>

<img src=\"images/sidePaperBottom.png\" alt=\"\" />
</div>

</p>

 

is not working, either ...

You should be developing and debugging your code on a system with error_reporting set to E_ALL and display_errors set to ON in you master php.ini so that all the php detected errors will be reported and displayed. You will save a TON of time.

 

In the first code in this thread and probably the last code as well, you would have gotten an undefined variable message since the $mySideBarPageData doesn't exist inside the function, as has been stated in the replies in this thread.

Here's where I'm confused:

 

if I put it in the page like this:

 

<?php echo $mySideBarPageData; ?>

 

It works fine.

 

 

When I try to pull it in with an included file, it doesn't work.

 

And I'm stuck trying to understand why it does not work.

Without the code that would be needed to reproduce the current problem, we cannot help much. It could be your include statement, how you are setting the variables, the php tags being used, the code in the included file being inside of a function...

 

However, I can just about guarantee that setting the error_reporting/display_errors settings as suggested would help pin down what is causing the problem.

Hi:

 

Let  me try the error reporting .. I assume in the php.ini file?

 

Sorry, I'm making the switch from old ASP to PHP and still trying to learn a lot of the tricks of the trade.

 

A bit frustrated cause I didn't think it would be so hard to get this to show up!

 

:)

 

Well, tried adding that to the php.ini file:

 

...
display_errors = ON
error_reporting = E_ALL
...

 

But, it's doing the same thing ...

 

Thanks for looking at it for me .. I guess I need to just add it to the code on each page ..

 

need to finish this up.

Well, tried adding that to the php.ini file

 

You need to restart your web server to get any changes made to the master php.ini to take effect and you need to confirm that the values actually changed using phpinfo() statement (in case the php.ini that you are changing is not the one that php is using.)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.