How to make the link 'index.php?x' display x section on a page












0















I was trying to make a site with different parts which will be shown with a questionmark (like index.php?notes, index.php?options, etc.). Normally I see this often on search query pages or blogs (with an ?q="question").



On my index.php page i have set multiple sections that will be shown if the user presses a href link.



I know that this can be done with the anchor link in css (with #options), but since I am using php, I would like to try that.



This is my code at the moment:



<body>
<p>
[<a href="?notes">Notes</a>]
[<a href="?categories">Categories</a>]
[<a href="?options">Options</a>]
</p>

<?php
if($display == 'categories') {
echo "<h4>Categories</h4>";
} else if ($display == "notes") {
echo "<h4>Delete Notes</h4>";
} else {
echo "<h4>Options</h4>";
}
?>
</body>









share|improve this question

























  • What is $display?

    – kerbholz
    Jan 2 at 13:03
















0















I was trying to make a site with different parts which will be shown with a questionmark (like index.php?notes, index.php?options, etc.). Normally I see this often on search query pages or blogs (with an ?q="question").



On my index.php page i have set multiple sections that will be shown if the user presses a href link.



I know that this can be done with the anchor link in css (with #options), but since I am using php, I would like to try that.



This is my code at the moment:



<body>
<p>
[<a href="?notes">Notes</a>]
[<a href="?categories">Categories</a>]
[<a href="?options">Options</a>]
</p>

<?php
if($display == 'categories') {
echo "<h4>Categories</h4>";
} else if ($display == "notes") {
echo "<h4>Delete Notes</h4>";
} else {
echo "<h4>Options</h4>";
}
?>
</body>









share|improve this question

























  • What is $display?

    – kerbholz
    Jan 2 at 13:03














0












0








0








I was trying to make a site with different parts which will be shown with a questionmark (like index.php?notes, index.php?options, etc.). Normally I see this often on search query pages or blogs (with an ?q="question").



On my index.php page i have set multiple sections that will be shown if the user presses a href link.



I know that this can be done with the anchor link in css (with #options), but since I am using php, I would like to try that.



This is my code at the moment:



<body>
<p>
[<a href="?notes">Notes</a>]
[<a href="?categories">Categories</a>]
[<a href="?options">Options</a>]
</p>

<?php
if($display == 'categories') {
echo "<h4>Categories</h4>";
} else if ($display == "notes") {
echo "<h4>Delete Notes</h4>";
} else {
echo "<h4>Options</h4>";
}
?>
</body>









share|improve this question
















I was trying to make a site with different parts which will be shown with a questionmark (like index.php?notes, index.php?options, etc.). Normally I see this often on search query pages or blogs (with an ?q="question").



On my index.php page i have set multiple sections that will be shown if the user presses a href link.



I know that this can be done with the anchor link in css (with #options), but since I am using php, I would like to try that.



This is my code at the moment:



<body>
<p>
[<a href="?notes">Notes</a>]
[<a href="?categories">Categories</a>]
[<a href="?options">Options</a>]
</p>

<?php
if($display == 'categories') {
echo "<h4>Categories</h4>";
} else if ($display == "notes") {
echo "<h4>Delete Notes</h4>";
} else {
echo "<h4>Options</h4>";
}
?>
</body>






php html mysql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 13:03







Mr. Plopkoek

















asked Jan 2 at 13:00









Mr. PlopkoekMr. Plopkoek

185




185













  • What is $display?

    – kerbholz
    Jan 2 at 13:03



















  • What is $display?

    – kerbholz
    Jan 2 at 13:03

















What is $display?

– kerbholz
Jan 2 at 13:03





What is $display?

– kerbholz
Jan 2 at 13:03












3 Answers
3






active

oldest

votes


















1














When using ?q=question you can access it in PHP via $_GET['q']. In your case, since you don't have q set, but ?notes you need to access it via $_GET['notes']. Try this:



<?php

if (isset($_GET['categories'])) {
echo "<h4>Categories</h4>";
} elseif (isset($_GET['notes'])) {
echo "<h4>Delete Notes</h4>";
} else {
echo "<h4>Options</h4>";
}





share|improve this answer



















  • 1





    Thank you, it works as expected!

    – Mr. Plopkoek
    Jan 2 at 13:17



















0














You could set a GET variable p and read that; e.g.



<a href="?p=notes">notes</a> and in PHP $_GET['p']






share|improve this answer































    0














    if you don't want to use any keys, then you can use this code:



    if(isset($_GET)){
    $page = key($_GET);
    }


    But this solution is not very good it can mess your code later. I suggest to use with key i.e. ?p=notes






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006852%2fhow-to-make-the-link-index-phpx-display-x-section-on-a-page%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      When using ?q=question you can access it in PHP via $_GET['q']. In your case, since you don't have q set, but ?notes you need to access it via $_GET['notes']. Try this:



      <?php

      if (isset($_GET['categories'])) {
      echo "<h4>Categories</h4>";
      } elseif (isset($_GET['notes'])) {
      echo "<h4>Delete Notes</h4>";
      } else {
      echo "<h4>Options</h4>";
      }





      share|improve this answer



















      • 1





        Thank you, it works as expected!

        – Mr. Plopkoek
        Jan 2 at 13:17
















      1














      When using ?q=question you can access it in PHP via $_GET['q']. In your case, since you don't have q set, but ?notes you need to access it via $_GET['notes']. Try this:



      <?php

      if (isset($_GET['categories'])) {
      echo "<h4>Categories</h4>";
      } elseif (isset($_GET['notes'])) {
      echo "<h4>Delete Notes</h4>";
      } else {
      echo "<h4>Options</h4>";
      }





      share|improve this answer



















      • 1





        Thank you, it works as expected!

        – Mr. Plopkoek
        Jan 2 at 13:17














      1












      1








      1







      When using ?q=question you can access it in PHP via $_GET['q']. In your case, since you don't have q set, but ?notes you need to access it via $_GET['notes']. Try this:



      <?php

      if (isset($_GET['categories'])) {
      echo "<h4>Categories</h4>";
      } elseif (isset($_GET['notes'])) {
      echo "<h4>Delete Notes</h4>";
      } else {
      echo "<h4>Options</h4>";
      }





      share|improve this answer













      When using ?q=question you can access it in PHP via $_GET['q']. In your case, since you don't have q set, but ?notes you need to access it via $_GET['notes']. Try this:



      <?php

      if (isset($_GET['categories'])) {
      echo "<h4>Categories</h4>";
      } elseif (isset($_GET['notes'])) {
      echo "<h4>Delete Notes</h4>";
      } else {
      echo "<h4>Options</h4>";
      }






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Jan 2 at 13:10









      kerbholzkerbholz

      2,16221119




      2,16221119








      • 1





        Thank you, it works as expected!

        – Mr. Plopkoek
        Jan 2 at 13:17














      • 1





        Thank you, it works as expected!

        – Mr. Plopkoek
        Jan 2 at 13:17








      1




      1





      Thank you, it works as expected!

      – Mr. Plopkoek
      Jan 2 at 13:17





      Thank you, it works as expected!

      – Mr. Plopkoek
      Jan 2 at 13:17













      0














      You could set a GET variable p and read that; e.g.



      <a href="?p=notes">notes</a> and in PHP $_GET['p']






      share|improve this answer




























        0














        You could set a GET variable p and read that; e.g.



        <a href="?p=notes">notes</a> and in PHP $_GET['p']






        share|improve this answer


























          0












          0








          0







          You could set a GET variable p and read that; e.g.



          <a href="?p=notes">notes</a> and in PHP $_GET['p']






          share|improve this answer













          You could set a GET variable p and read that; e.g.



          <a href="?p=notes">notes</a> and in PHP $_GET['p']







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 2 at 13:07









          Erik TerwanErik Terwan

          1,8811326




          1,8811326























              0














              if you don't want to use any keys, then you can use this code:



              if(isset($_GET)){
              $page = key($_GET);
              }


              But this solution is not very good it can mess your code later. I suggest to use with key i.e. ?p=notes






              share|improve this answer




























                0














                if you don't want to use any keys, then you can use this code:



                if(isset($_GET)){
                $page = key($_GET);
                }


                But this solution is not very good it can mess your code later. I suggest to use with key i.e. ?p=notes






                share|improve this answer


























                  0












                  0








                  0







                  if you don't want to use any keys, then you can use this code:



                  if(isset($_GET)){
                  $page = key($_GET);
                  }


                  But this solution is not very good it can mess your code later. I suggest to use with key i.e. ?p=notes






                  share|improve this answer













                  if you don't want to use any keys, then you can use this code:



                  if(isset($_GET)){
                  $page = key($_GET);
                  }


                  But this solution is not very good it can mess your code later. I suggest to use with key i.e. ?p=notes







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Jan 2 at 13:11









                  JohnnyB1988JohnnyB1988

                  1467




                  1467






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006852%2fhow-to-make-the-link-index-phpx-display-x-section-on-a-page%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules