Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Get ID

  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    32
    Thanks
    12
    Thanked 0 Times in 0 Posts

    Get ID

    Hi all, a little help if you can, please

    I have a piece of code that give a page an ID. which is below

    PHP Code:
    <?php
    if (isset($_GET['id']))
       {
       
    $Id $_GET['id'];
       }
    else
       {
       
    $Id '326';
       }
    ?>
    Once the page has fully loaded in a browser, how would I display what this page ID is?
    I have tried the below code, but it doesn't work (displays nothing)

    PHP Code:
    <?php echo "" $_GET["id"] . ""?>')">

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Your second block assumes that $_GET['id'] is present. The first does not, and provides $Id a value if its not available.
    Simply use $Id instead of $_GET['id']. Since you currently display nothing, that infers that you have no querystring passed to the script, so you'll need to provide it with $Id to get the default value of 326.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    mulder (05-28-2013)

  • #3
    Junsee
    Guest
    PHP Code:
    <?php
    if ($_GET['id']) {
          
    $Id $_GET['id'];
       } else {
          
    $Id '326';
       }


    echo 
    '<p><a href="'.$_SERVER['PHP_SELF'].'?id=123">ClickHere to Set GET</a></p>';
    echo 
    '<p><a href="'.$_SERVER['PHP_SELF'].'">ClickHere to Unset GET</a></p>';

    echo 
    '<p>The GET ID is: '.$_GET['id'].' </p>';
    echo 
    '<p>The ID Variable: '.$Id.'</p>';
    ?>
    play around with the above code should give you some helpful pointers

  • Users who have thanked Junsee for this post:

    mulder (05-28-2013)

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    32
    Thanks
    12
    Thanked 0 Times in 0 Posts
    thanks for the help guys, I got there in the end but could not have done without you

  • #5
    New Coder
    Join Date
    Dec 2011
    Posts
    61
    Thanks
    4
    Thanked 10 Times in 10 Posts
    Something like this?
    PHP Code:
     <?php
    if (isset($_GET['id'])) {
          
    $Id $_GET['id'];
       } else {
          
    $Id '326';
       }


    echo 
    '<p><a href="'.$_SERVER['PHP_SELF'].'?id=123">ClickHere to Set GET</a></p>';
    echo 
    '<p><a href="'.$_SERVER['PHP_SELF'].'">ClickHere to Unset GET</a></p>';

    echo (isset(
    $_GET['id'])) ? '<p>The GET ID is: '.$_GET['id'].' </p>' '<p>The ID Variable: '.$Id.'</p>';

    ?>
    True courage is about knowing not when to take a life, but when to spare one. PDO Login Tutorial


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •