smartguyin Posted January 2, 2007 Share Posted January 2, 2007 In my index.php i had included header.php and footer.phpMy index.php page[code]<?include "header.php//////// BODYinclude "footer.php?>[/code]My header.php page[code]<?echo "<html><head><title>$titlename</title><head><body>";?>[/code]My footer.php page[code]<?///// the variable $title i got it from database here$row['title'] = $titlename;///// I WANT TO USE THIS $titlename IN HEADER.PHPecho "</body></html>";?>[/code]Now in header file there is title tag.... i want to use one $var variable from footer.php file but i am not able to do it coz footer.php file is included after header.php...... sooo i cannot get the Title in header.php file to be displayed........footer.php file is the main body which interacts with mysql database and works.... sooo i suppose there is product title stated as a variable in footer.php i want to use tht variable in header.php .........please tell me how to do it........... Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/ Share on other sites More sharing options...
trq Posted January 2, 2007 Share Posted January 2, 2007 [quote]please tell me how to do it[/quote]The only way is to include the footer before the header. PHP runs from top down, you will need to rethink your logic. Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-151319 Share on other sites More sharing options...
lice200 Posted January 2, 2007 Share Posted January 2, 2007 Put the $vars in index.php instead of each file then just echo it in header and footer. Then include index.php; in footer and header.php. Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-151320 Share on other sites More sharing options...
smartguyin Posted January 3, 2007 Author Share Posted January 3, 2007 Can i use funtions to do this thing ????Can functione help me to get things from footer.php and use it in header.phpI know its possible by function can any one explain me the logic which i can use. Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-152242 Share on other sites More sharing options...
ober Posted January 3, 2007 Share Posted January 3, 2007 Well... chances are you're going to run your footer function AFTER your header function, so your point is moot anyways. You're going to have to run the code for the footer in both locations and just not do the display part in the header for the footer.... or just run the code in the header... the variable will still be available for the footer when you include it. Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-152245 Share on other sites More sharing options...
trq Posted January 3, 2007 Share Posted January 3, 2007 [quote]can any one explain me the logic which i can use[/quote]You cannot use variables before they are difined. However, if you wrap your variable within a function, you can call this function before its defined. eg;[code]<?php $foo = bar(); echo $foo; function bar() { return "this is foo"; }?>[/code]This is of course a poor way of getting around your problem however. Ideally you need to restructure your entire logic so that it runs from top -> bottom. Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-152249 Share on other sites More sharing options...
smartguyin Posted January 3, 2007 Author Share Posted January 3, 2007 I had solved my prblem by using this belowi used function to get wht i wanted.... in header.php i used function setup_page ($title) {<html><head><title>$title</title></head>}In footer.php setup_page("$row['title']")And in this was i was able to trf the content i want from footer to header.php Quote Link to comment https://forums.phpfreaks.com/topic/32546-solved-using-variable-of-footerphp/#findComment-152382 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.