php ?=

  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

I know this is going to sound stupid probably, but anyway i have never used this thing befor. Ok lets say that i have a link like this a href="index.php?id=something" how can I make the php take me to display a portion of the site that is under the value something!?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • alex89
  • Bronze Member
  • Bronze Member
  • User avatar
  • Posts: 239
  • Loc: Western Australia

Post 3+ Months Ago

Try mucking around with something like this (for index.php):

Code: [ Select ]
<?

$location = $_POST['id'];
header( 'Location: ' & $location );

?>
  1. <?
  2. $location = $_POST['id'];
  3. header( 'Location: ' & $location );
  4. ?>
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

What your seeing in that url is called a query string, basically its everything that comes after the question mark.

To get a specific item from the list you can use the server var $_REQUEST['id'] or $_GET['id'].
  • seularts
  • Graduate
  • Graduate
  • User avatar
  • Posts: 153
  • Loc: Romania

Post 3+ Months Ago

i must specify that this is not a db project, it's experimental for a plain text menu:)
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

okay then you'll have something like the following:
Code: [ Select ]
<?php
switch ($_GET['id']) //switch statement ... query string
{
case "one":
echo "<h1>First Choice</h1>"; // echo statement
echo "<p>That was the first choice</p>";
break;
case "two":
echo "<h1>Second Choice</h1>";
echo "<p>That was the second choice</p>";
break; // break statement
}
?>
  1. <?php
  2. switch ($_GET['id']) //switch statement ... query string
  3. {
  4. case "one":
  5. echo "<h1>First Choice</h1>"; // echo statement
  6. echo "<p>That was the first choice</p>";
  7. break;
  8. case "two":
  9. echo "<h1>Second Choice</h1>";
  10. echo "<p>That was the second choice</p>";
  11. break; // break statement
  12. }
  13. ?>
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

Those variables still apply.

http://www.tizag.com/phpT/postget.php
  • X3ndou
  • Proficient
  • Proficient
  • User avatar
  • Posts: 263
  • Loc: New Jersey

Post 3+ Months Ago

Unless your server for some reason has register globals off you can just do this

PHP Code: [ Select ]
<?php
 
if ($id == "display") {
  echo ("Display portion!");
}
 
?>
  1. <?php
  2.  
  3. if ($id == "display") {
  4.   echo ("Display portion!");
  5. }
  6.  
  7. ?>


If you've got lots of pages use a switch.
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

X3ndou wrote:
Unless your server for some reason has register globals off you can just do this


Most server run register globals off, and if they don't its a good idea to turn them off in your .htaccess file.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 125 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.