87dave87 Posted November 15, 2006 Share Posted November 15, 2006 Hi,I have created this code to automatically create browser titles: -[code]<? $url = $_SERVER['REQUEST_URI']; if($url == '/') { echo "<title>emulators.cc - console and handheld for blah de blah</title>"; }if(strpos($url, "about")!== false) { echo "<title>emulators.cc > About Us</title>"; }if(strpos($url, "windows")!== false) { echo "<title>emulators.cc > Windows Emulators > "; echo $row['platform']; echo "</title>"; }if(strpos($url, "mac")!== false) { echo "<title>emulators.cc > Mac Emulators > "; echo $row['platform']; echo "</title>"; }if(strpos($url, "linux")!== false) { echo "<title>emulators.cc > Linux Emulators > "; echo $row['platform']; echo "</title>"; }else { echo "<title>emulators.cc</title>"; }?> [/code]The way this works is if 'windows' is in the url, e.g. www.emulators.cc/windows/ then it displays 'emulators.cc > Windows Emulators > ' in the title, the problem comes with echo $row['platform']; which should display a the result of a field from my database which contains the platform an emulator is based, e.g. Atari 2600. So then the title would be 'emulators.cc > Windows Emulators > Atari 2600'The above code is placed in my head.php include, before this include is called to on my sub page (e.g. emulators.cc/windows/atari2600/) I have this code (which is the query): -[code]<?include($_SERVER['DOCUMENT_ROOT'] . '/includes/dbconnect.php'); $query = mysql_query("SELECT platform FROM windows_atari2600 limit 0,1");$row = mysql_fetch_assoc($query);include($_SERVER['DOCUMENT_ROOT'] . '/includes/head.php');?>[/code]This should work fine as the query is there, and then when head.php is included, it should show the platform (it does work if the query is put into the head.php include). So why doesnt it work outside the head.php include?Thanks again! Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/ Share on other sites More sharing options...
trq Posted November 15, 2006 Share Posted November 15, 2006 i dont even understand why you need a database or query for this, your query will allways return the same result, why not just hard code that result? Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124946 Share on other sites More sharing options...
87dave87 Posted November 15, 2006 Author Share Posted November 15, 2006 It is the same everytime because in my search box for this site there can be various emulators with the same platform but with different operating systems.Using the $platform idea they are generated straight from when I update the database. Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124949 Share on other sites More sharing options...
trq Posted November 15, 2006 Share Posted November 15, 2006 Ok then, sorry, but there is no reason this shouldn't be working then. Unless of course the query is failing. You do fail to check it actually succeeds before using it. Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124956 Share on other sites More sharing options...
87dave87 Posted November 15, 2006 Author Share Posted November 15, 2006 If I put the query code directly into the head.php file, it works.[code]<? $url = $_SERVER['REQUEST_URI']; $query = mysql_query("SELECT platform FROM windows_atari2600 limit 0,1");$row = mysql_fetch_assoc($query);if($url == '/') { echo "<title>emulators.cc - console and handheld for blah de blah</title>"; }if(strpos($url, "about")!== false) { echo "<title>emulators.cc > About Us</title>"; }if(strpos($url, "windows")!== false) { echo "<title>emulators.cc > Windows Emulators > "; echo $row['platform']; echo "</title>"; }if(strpos($url, "mac")!== false) { echo "<title>emulators.cc > Mac Emulators > "; echo $row['platform']; echo "</title>"; }if(strpos($url, "linux")!== false) { echo "<title>emulators.cc > Linux Emulators > "; echo $row['platform']; echo "</title>"; }else { echo "<title>emulators.cc</title>"; }?> [/code]So everything must be fine, but then when I move the query to the subpage, it doesnt.. does php allow variables to be passed to included files? Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124963 Share on other sites More sharing options...
Orio Posted November 15, 2006 Share Posted November 15, 2006 You dont have an option to allow/disallow php to transfer variables, they always do. Think of include() (or require()) as a function that writes ?> then puts all the content of the included file in the place where it was called, and then writes <?php.So there's some problem with the inluding / with the query. The variables are "passed" to the included file for sure.Orio. Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124965 Share on other sites More sharing options...
87dave87 Posted November 15, 2006 Author Share Posted November 15, 2006 ok this is working now, was a problem with the code from dbconnect file ending php statement Link to comment https://forums.phpfreaks.com/topic/27331-variable-not-going-over-to-a-page-included/#findComment-124967 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.