spacepoet Posted May 5, 2011 Share Posted May 5, 2011 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 ?? Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/ Share on other sites More sharing options...
JKG Posted May 5, 2011 Share Posted May 5, 2011 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.. Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211017 Share on other sites More sharing options...
wildteen88 Posted May 5, 2011 Share Posted May 5, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211024 Share on other sites More sharing options...
spacepoet Posted May 5, 2011 Author Share Posted May 5, 2011 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 ... Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211033 Share on other sites More sharing options...
PFMaBiSmAd Posted May 5, 2011 Share Posted May 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211036 Share on other sites More sharing options...
spacepoet Posted May 5, 2011 Author Share Posted May 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211174 Share on other sites More sharing options...
PFMaBiSmAd Posted May 5, 2011 Share Posted May 5, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211177 Share on other sites More sharing options...
spacepoet Posted May 5, 2011 Author Share Posted May 5, 2011 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! Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211185 Share on other sites More sharing options...
spacepoet Posted May 6, 2011 Author Share Posted May 6, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211217 Share on other sites More sharing options...
PFMaBiSmAd Posted May 6, 2011 Share Posted May 6, 2011 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.) Quote Link to comment https://forums.phpfreaks.com/topic/235622-how-can-i-display-this-from-an-included-file/#findComment-1211363 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.