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
https://forums.phpfreaks.com/topic/47324-new-to-php/
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
https://forums.phpfreaks.com/topic/47324-new-to-php/#findComment-230883
Share on other sites

hehe, ofcourse that only ansvered half my question:P

 

now i want to add a function that imagine looks something like this: if $_get=("contact") include("contact.php")

 

was that understandable?

 

if you go here: http://www.zendurl.com/kleistad/mondayrock/index.php  you´ll probably understand what i want to do!

 

Link to comment
https://forums.phpfreaks.com/topic/47324-new-to-php/#findComment-230890
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
https://forums.phpfreaks.com/topic/47324-new-to-php/#findComment-230902
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
https://forums.phpfreaks.com/topic/47324-new-to-php/#findComment-230906
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
https://forums.phpfreaks.com/topic/47324-new-to-php/#findComment-230908
Share on other sites

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.