devilsvein Posted January 3, 2013 Share Posted January 3, 2013 I've basically created a function which hosts a image and text obtained from my database. Now this all works. The image shows and the correct information from the database is retrieved. IF i put it in a function....the text from the database isn't retrieved. the page that the function is on is as so: <?php require "corefolder/globe.php"; // global connection and data retrieval require "corefolder/gamecore.php"; function Banner() { echo "<div class=bannimage> <img src='newbann.png' /> <div class=text> <h3 style=margin-top:0px; margin-bottom:0px;>"; echo "["; echo $userid; echo "] " ; </div> </div>"; } ?> Link to comment https://forums.phpfreaks.com/topic/272668-some-understanding-of-a-function/ Share on other sites More sharing options...
Barand Posted January 4, 2013 Share Posted January 4, 2013 Check out variable scope http://php.net/manual/en/language.variables.scope.php Link to comment https://forums.phpfreaks.com/topic/272668-some-understanding-of-a-function/#findComment-1403094 Share on other sites More sharing options...
devilsvein Posted January 4, 2013 Author Share Posted January 4, 2013 Thanks for that barand. Works fine after I added global in... Link to comment https://forums.phpfreaks.com/topic/272668-some-understanding-of-a-function/#findComment-1403096 Share on other sites More sharing options...
Barand Posted January 4, 2013 Share Posted January 4, 2013 Whenever possible you should forget the existence of the word "global". A better solution is to pass the variable to the function as a parameter. Link to comment https://forums.phpfreaks.com/topic/272668-some-understanding-of-a-function/#findComment-1403098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.