Jump to content

[SOLVED] a href values


adrumsolo4u

Recommended Posts

i have been searching for a tutorial to explain to me how to do a simple task, but cannot find one.

here is what I'd like to do:

have a link such as this one <a href="?menu=1&sub='variable'">click me</a>

to allow a user to click, and for the link to output a constant (in this case, 1) and also gather a variable. ("variable")

then i will need code to find the values of both "menu" and "sub1" and have those values stored temporarily, until they are change by another link, such as

<a href="?menu='variable'&sub=1">click me too!</a>

 

i am not sure if i explained enough...

any suggestions?

Link to comment
Share on other sites

This may help as well...

<?php
  $code=myfunc($_GET['menu'],$_GET['variable']);
  ...
  function myfunc($menu,$var) { {
    if (empty($menu)||empty($var)) {
      $retvar=0;
    } else {
      if ($_GET['menu']=="1") {
        if ($_GET['variable']=="0") {
          echo "Menu 1, variable 0";
          $retvar=1;
        } else if ($_GET['variable']=="1") {
          echo "Menu 1, variable 1";
          $retvar=2;
        } else {
          echo "Menu 1, variable not known";
          $retvar=3;
        }
      } else {
        echo "Menu unknown";
        $retvar=4;
      }
    }
    return $retvar;
  }
?>

 

EDIT: Accidentally used different names for the function.

Link to comment
Share on other sites

what i'm trying to do is create a nav menu

if lets say "1" were clicked, the variable would become 1, and an if statement containing the two subs would allow it to print the html, while the subs from the other main categories (2,3,4) are not printed, because their if statement is not true.

 

1

+1.1

+1.2

2

3

4

 

 

Link to comment
Share on other sites

Had a feeling you were. Sorry for the delay in replying but I just had major problems getting this to display properly. Off the top of my head, can't guarantee it'll work first time.

<?php
  $menu=$_GET['menu'];
  $sub=$_GET['sub'];
  //Just so you can see what was pulled from the URL
  echo 'You selected '.$menu.((!empty($sub)) ? " and sub menu ".$sub : "").'<br /><br />';
  //Now we build the menu
  echo '<a href="menu.php?menu=1">Option 1</a><br />';
  if ($menu==1) {
    echo '<a href="menu.php?menu=1&sub=1">Menu 1 Sub 1</a><br />';
    echo '<a href="menu.php?menu=1&sub=2">Menu 1 Sub 2</a><br />';
  }
  echo '<a href="menu.php?menu=2">Option 2</a><br />';
  if ($menu==2) {
    echo '<a href="menu.php?menu=2&sub=1">Menu 2 Sub 1</a><br />';
    echo '<a href="menu.php?menu=2&sub=2">Menu 2 Sub 2</a><br />';
  }
  echo '<a href="menu.php?menu=3">Option 3</a><br />';
  if ($menu==3) {
    echo '<a href="menu.php?menu=3&sub=1">Menu 3 Sub 1</a><br />';
    echo '<a href="menu.php?menu=3&sub=2">Menu 3 Sub 2</a><br />';
  }
?>

Link to comment
Share on other sites

It's quite easy to add a hidden menu system although this wouldn't be secure and isn't really recommended for anything serious. Add this after the last if...

  if ($menu==2118) {
    echo '<a href="menu.php?menu=2118&sub=1">Menu secret Sub 1</a><br />';
    echo '<a href="menu.php?menu=2118&sub=2">Menu secret Sub 2</a><br />';
  }

That way you'd have to edit the URL in the address bar to change menu to the value of 2118 but only the sub menu would show and you'd never get a menu option for that secret menu showing.

 

All in the name of fun :D

Link to comment
Share on other sites

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.