monkeypaw201 Posted April 22, 2008 Share Posted April 22, 2008 i'm not sure im doing this right... <?php function sitename() { echo $row_Settings['airline_name']; } then to display it <?php sitename(); ?> its not working though.. Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/ Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Where are you getting $row_Settings? If it's from another part in the script, do: <?php function sitename() { global $row_Settings; echo $row_Settings['airline_name']; } ?> Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523581 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 Brilliant, but what does the global part do?? ??? ??? Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523582 Share on other sites More sharing options...
yankeesjtj Posted April 22, 2008 Share Posted April 22, 2008 Where are you getting $row_Settings? If it's from another part in the script, do: <?php function sitename() { global $row_Settings; echo $row_Settings['airline_name']; } ?> or if it's coming from another page you'd have to do something like <?php function sitename() { $row_Settings= $_REQUEST['row_Settings']; echo $row_Settings['airline_name']; } ?> Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523583 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 There's something called variable scope. You can't use outside variables inside a function unless you reference them as global. Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523584 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 @Yankee: NEVER use $_REQUEST. Just use $_GET, $_POST, or $_COOKIE. $_REQUEST is SO insecure. Don't use it. Please. Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523585 Share on other sites More sharing options...
intodesi Posted April 22, 2008 Share Posted April 22, 2008 Wow so one could create functions to hold repetive data, stick all of them in one file, and then include that file, then all you have to do is just type <?php sitename(); ?> wherever you need that particular function? sorry to change the subject.. just had to comment.. L:P Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523587 Share on other sites More sharing options...
DarkWater Posted April 22, 2008 Share Posted April 22, 2008 Wow so one could create functions to hold repetive data, stick all of them in one file, and then include that file, then all you have to do is just type <?php sitename(); ?> wherever you need that particular function? sorry to change the subject.. just had to comment.. L:P Probably wouldn't want to do that though. Depends on the situation. Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523588 Share on other sites More sharing options...
monkeypaw201 Posted April 22, 2008 Author Share Posted April 22, 2008 sorry to re-open, but i just went and it seems really weird... i have that same code, but to make it display i have to put <?php echo sitename(); ?> even after i already echoed in the function, it works in some cases, but not others, any suggestions? EDIT:: i figured it would help if i put the code is causing problems with; href ="<?php fullurl() . "Themes" . $row_Settings['theme_directory']; ?>Style/style.css" /> when the function is <?php function fullurl() { global $row_Settings; echo $row_Settings['base_url'] . $row_Settings['directory']; } ?> the problem is that it actually prints that on the page while the page is loading... Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523590 Share on other sites More sharing options...
yankeesjtj Posted April 22, 2008 Share Posted April 22, 2008 @Yankee: NEVER use $_REQUEST. Just use $_GET, $_POST, or $_COOKIE. $_REQUEST is SO insecure. Don't use it. Please. OK, thanks DarkWater... had no Idea, guess I should redo all my scripts then... Link to comment https://forums.phpfreaks.com/topic/102261-solved-function-help/#findComment-523593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.