The online racing simulator
PHP help plz
(15 posts, started )
PHP help plz
sorry for askin here noob questions but i really need help

im starting php and first try is to make a menu index.php with submenus in style like:

index.php?page=1 -> and then link that to page 1...


<div id="menu">
<ul>
<li><a href="index.php?page=home">Home</a></li>
<li><a href="index.php?page=1">Test 1</a></li>
<li><a href="index.php?page=2">Test 2</a></li>
</ul>

<?php

if(isset($_GET['page']) && $_GET['page'] == 'home')
{
include 'index.php';
}

if(isset($_GET['page']) && $_GET['page'] == '1')
{
include 'test1.php';
}

if(isset($_GET['page']) && $_GET['page'] == '2')
{
include 'test2.php';
}

?>
</div>

but that doesnt seem to work, what did i do wrong?
Switch Statments in PHP.
Try a switch statement.


<?php 
<html>
    <
head>
        <
title>Page Title</title>
    </
head>
    <
body>
        <
div id="head"></div>
        <
div id="body">
            <
div id="menu">
                <
ul>
                    <
li><a href="index.php?page=home">Home</a></li>
                    <
li><a href="index.php?page=1">Test 1</a></li>
                    <
li><a href="index.php?page=2">Test 2</a></li>
                </
ul>
            </
div>
            <
div id="main">
php
    
switch ($_GET['page']) {
        case 
1:
            @include(
'./page1.php');
        break;
        case 
2:
            @include(
'./page2.php');
        break;
        default:
        case 
'Home':
            @include(
'./home.php');
        break;
    }

            </
div>
        </
div>
        <
div id="foot"></div>
    </
body>
</
html>
?>

Maybe $_GET is out of scope. Try ...

global $_GET;

... before you start accessing it.
Quote from thisnameistaken :Maybe $_GET is out of scope. Try ...

global $_GET;

... before you start accessing it.

While, you might be talking about some wierd error that comes into PHP (that I've never heard of, so it this does fix your problem please do tell). $_GET itself is a super global, and should be global by default.
While I am at it, I will say that it's pretty bad form to have the same condition be asked of multiple if statements.


<?php 
php
    
if (isset($_GET['page']) === TRUE) {
        if (
$_GET['page'] == 1)
            include(
'./page1.php');
        else if (
$_GET['page'] == 2)
            include(
'./page2.php');
        else if (
strtolower('./home.php');
        else
            include(
'./default.php');
    } else {
        @include(
'./default.php');
    }
?>

Quote from Dygear :$_GET itself is a super global, and should be global by default.

Oh yeah... Sorry, I was thinking of $HTTP_GET_VARS.
hmm it loops the links endless ... , maybe u wanna see yourself click here
Try this:
Quote : <div id="menu">
<ul>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>?page=home">Home</a></li>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>
?page=1">Test 1</a></li>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>
?page=2">Test 2</a></li>
</ul>

<?php

if($_GET["page"] == 'home')
{
include('test0.php');
}

if($_GET["page"] == 1)
{
include('test1.php');
}

if($_GET["page"] == 2)
{
include('test2.php');
} ?>
</div>

I hope it is working

All included files shouldn´t check $_GET["page"], because than it is a fictional while function
Quote from janwolf :Try this:

I hope it is working

All included files shouldn´t check $_GET["page"], because than it is a fictional while function

damn its still looping ...
Quote from GeForz :what exactly does your code look like?


<html>
<head>
<title>Page Title</title>
</head>
<body>
<div id="head"></div>
<div id="body">
<div id="menu">
<ul>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>?page=home">Home</a></li>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>?page=1">Test 1</a></li>
<li><a href="<?php print $_SERVER["PHP_SELF"];?>?page=2">Test 2</a></li>
</ul>
</div>
<div id="main">
<?php

if($_GET["page"] == 'home')
{
include('index.php');
}

if($_GET["page"] == 1)
{
include('1.php');
}

if($_GET["page"] == 2)
{
include('2.php');
} ?>

<h1> 1.php</h1>

</div>
</div>
<div id="foot"></div>
</body>
</html>

index.php , 1.php and 2.php same code just that at <h1> always shown what file it is. index.php -> h1=index.php , 1.php -> h1=1.php, ... blah just to see what php is openend...

when i open index.php and click f.ex. 1.php then it loops showing this php under each other...

all files at www.???.de/test/ for testing
Well if 1.php and 2.php have the same code, the action will repeat on and on. For example i´ll demonstrate what the parser is thinking by $_GET = 1; if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ include(1.php); ............ } } } } } } Because you are including the same. 1.php 2.php .... must written without that code!!!!! ummm the structure is breaking:P
Quote from janwolf :Well if 1.php and 2.php have the same code, the action will repeat on and on. For example i´ll demonstrate what the parser is thinking by $_GET = 1; if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ if($_GET = 1){ include(1.php); ............ } } } } } } Because you are including the same. 1.php 2.php .... must written without that code!!!!! ummm the structure is breaking:P

yeah but how can i use in 1.php or 2.php the menu when i leave out the code`? or do i think totally wrong ?!
just make one file "index.php" wich includes the above php code. Then make a home.php, 1.php, 2.php with CONTENT; NOT the menu.

=> index.php

<?php 
<html
    <
head
        <
title>Page Title</title
    </
head
    <
body
        <
div id="head"></div
        <
div id="body"
            <
div id="menu"
                <
ul
                <
li><a href="index.php?page=home">Home</a></li>
                <
li><a href="index.php?page=1">Test 1</a></li>
                <
li><a href="index.php?page=2">Test 2</a></li>
                </
ul>
            </
div
            <
div id="main"


if(
$_GET["page"] == 'home'

include([
B]'home.php[/B]'); 


if(
$_GET["page"] == 1

include(
'1.php'); 


if(
$_GET["page"] == 2

include(
'2.php');


<
h11.php</h1>

            </
div
        </
div
        <
div id="foot"></div
    </
body
</
html>
?>

Notice how every link linkes to index.php wich contains the code and how each include includes a file which is NOT including the code
Quote from GeForz :just make one file "index.php" wich includes the above php code. Then make a home.php, 1.php, 2.php with CONTENT; NOT the menu.

=> index.php

<?php 
<html
    <
head
        <
title>Page Title</title
    </
head
    <
body
        <
div id="head"></div
        <
div id="body"
            <
div id="menu"
                <
ul
                <
li><a href="index.php?page=home">Home</a></li>
                <
li><a href="index.php?page=1">Test 1</a></li>
                <
li><a href="index.php?page=2">Test 2</a></li>
                </
ul>
            </
div
            <
div id="main"


if(
$_GET["page"] == 'home'

include([
b]'home.php[/b]'); 


if(
$_GET["page"] == 1

include(
'1.php'); 


if(
$_GET["page"] == 2

include(
'2.php');


<
h11.php</h1>

            </
div
        </
div
        <
div id="foot"></div
    </
body
</
html>
?>

Notice how every link linkes to index.php wich contains the code and how each include includes a file which is NOT including the code

aaah damn now i understand how this works ^^ thanx a lot

PHP help plz
(15 posts, started )
FGED GREDG RDFGDR GSFDG