Jump to content

New to PHP!


kleistad

Recommended Posts

Hello everybody!

 

I´ve just started learning PHP, an now i have a question.

 

im using my index.php file as the "main" page, and when you press a link i just want the page to include another file in one of the table windows, how do I do this?

 

I knew ASP before and rember something about "query string", can someone give me the code in PHP?

 

thanks

Link to comment
Share on other sites

I'm a bit confused by your terminology.  By "table window", do you mean a particular table in the html, such as a large table in the center of the page?

 

An example of a website which does what you want would help.

Link to comment
Share on other sites

The equivalent of the Request.QueryString function in ASP is the $_GET variable in PHP.  $_GET is used to access the querystring paramters, example:

On index.php?page=mypage, the following script:

<?php
print $_GET['page'];
?>

Would print "mypage".  Other than that I am unaware of your question.

Link to comment
Share on other sites

Try this one:

 

<?php
$validPages = array(
     'main' => 'pagetoload.php',
     'press' => 'press.php',
     'about' => 'about.php',
     'music' => 'music.php',
     'contact' => 'contact.php'
);
$page = isset($_GET['page']) && in_array($_GET['page'], $validPages) ? strtolower($_GET['page']) : 'main';
include $validPages[$page];
?>

Link to comment
Share on other sites

<?php

$validPages = array(

    'main' => 'main.php',

    'press' => 'press.php',

    'about' => 'about.php',

    'music' => 'music.php',

    'contact' => 'contact.php'

);

$page = isset($_GET['page']) && in_array($_GET['page'], $validPages) ? strtolower($_GET['page']) : 'main';

include $validPages[$page];

?>

 

i´ve done like this, but no matter what link I press, it will only load main.php... know why?

Link to comment
Share on other sites

I apologize, it should be:

 

<?php
$validPages = array(
     'main' => 'main.php',
     'press' => 'press.php',
     'about' => 'about.php',
     'music' => 'music.php',
     'contact' => 'contact.php'
);
$page = isset($_GET['page']) && array_key_exists(strtolower($_GET['page']), $validPages) ? strtolower($_GET['page']) : 'main';
include $validPages[$page];
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.