Jump to content

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>

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.