Jump to content

[SOLVED] Display an page after clicking a link


konetch

Recommended Posts

I have two files: newlink.php and index.php

 

IN newlink.php I have a class where I want it so that when one function is excecuted the other one will display. TO make myself clearer I want it so that when I click a link like localhost/index.php?post=1 it will come up with

 

HELLO World

 

Understand.

 

Here are the two files

 

newlink.php

<?php

class newlink {

  public function displayLink () {

?>
    <a href="<?php echo $_SERVER['PHP_SELF']; ?>?post=1">Read my first page!!!</a>
<?php
  }

  public function displayPage () {
?>
    <h2>Hello World</h2>
    <p>This is a test post</p>
<?php
  }
}
?> 

 

index.php

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Home</title>
  </head>

  <body>
<?php

  require_once("newlink.php");

    $obj = new newlink();

    echo  $obj->displayLink();

?>
  </body>
</html>

 

I've got most of it down I think I just need something that will diplay the post when I click the link. Can you tell me how to do this. Thanks

 

If I'm not clear enough jsut ask. I'll reply quickly

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>Home</title>
  </head>

  <body>
<?php

  require_once("newlink.php");

    $obj = new newlink();
if (isset($_GET["page"]) && $_GET["page"] == 1) {
    echo $obj->displayPage();
} else {
    echo  $obj->displayLink();
}
?>
  </body>
</html>

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.