0

Want to include another value in my urls

so far I have

   # valid pages
  $page = array('splash', 'portraits', 'weddings', 'studio', 'about', 'mobile',      'personal');

 # validate GET, default to splash if not provided
 $_GET['q'] = (isset($_GET['q'])) ? strtolower(trim($_GET['q'])) : 'splash';
 if (!in_array($_GET['q'], $page))
 $_GET['q'] = 'splash';

require_once "{$_GET['q']}.html";

but I want to include sections into my site so I need an extra value (ie. ?q=portraits?z=studio )

I assume I could probably just duplicate the $get command and replace q with z... but suppose I don't want the second value to be necessary (so the default pages will display without extra commands) and i want it to target a div or frame within the page? Not sure if I can even target divs.

3
  • 2
    Should be ?q=portraits&z=studio not ?q=portraits?z=studio. Also, your ifstatement in code is quite ambiguous. Wrap it with curly braces. Commented Aug 3, 2011 at 22:25
  • 2
    We know it's a "question", and we know it's about HTML/PHP. Can you improve your question title to actually describe the problem? Commented Aug 3, 2011 at 22:31
  • @user482594: It's not "ambiguous" in any way at all. (Hard to read, possibly.) Commented Aug 3, 2011 at 22:32

1 Answer 1

1

Just use a default value:

if (isset($_GET['z'])) {
    $z = $_GET['z'];
}
else {
    $z = NULL; // or 'default' or whatever you want.
}

You can in short write the above in one line:

$z = isset($_GET['z']) ? $_GET['z'] : NULL;

I am not sure what you mean with "target a div", but if you mean an anchor, you can do that via identifiers (id).

Call your PHP script via index.php?q=splash#text and in your splash.html file you somewhere have <div id="splash">. The browser should scroll there.

Sign up to request clarification or add additional context in comments.

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.