Jump to content

Variable not going over to a page included


87dave87

Recommended Posts

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!
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?
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.