0

For example:

if I just have cite.php, it would default to something

if it is cite.php?c=1, then it would load other content.

same as cite.php?c=2 ....etc

I did it before using a switch,case statement but I forgot how to do it :(

5 Answers 5

3
$f = $_GET["c"];

switch($f){
  case 1:
    /* content here*/
  break;

  case 2:
  /* content here*/
  break;
}
Sign up to request clarification or add additional context in comments.

1 Comment

What happens if $f is null? :)
1

You may use this code:

        $c = isset($_GET['c'])?$_GET['c'] : ''; 
    switch ($c) {

    case 1:
        /* Do something related to 1 */
        break;
    case 2:
        /* Do something related to 2 */
        break;
    default:
      /* Do something related to default */
    }

Comments

0

You can use the &_GET variable:

<?php echo $_GET["c"]; ?>

Comments

0

you'll use $_GET[]

if isset($_GET['c']) {
    /* write code to show specific info *?
} else {
    /* show other info here */
}

Comments

0

you can do this much simpler with if statements

place this code in the header page

<?php 

$page = $_GET['c'];

if(!isset($page)) {
    header('location:cite.php?c=1');
    exit;
}

?>

then use this to load display different element on the page(place between <body></body> tags)

<? if ($page == "1") {?>

<h2>page 1</h2>

<? } else if ($page == "2") { ?>
<h2>page 2</h2>


<? } ?>

and the links will look like this

<a herf="cite.php?c=1">Link 1</a> <a herf="cite.php?c=2">Link 2</a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.