PHP字段未知的PHP ID [重复]

This question already has an answer here:

I am trying to display a pages ID which is created from a table field. Currently I have this setup

    if (isset($_GET['id']))
   {
   $Id = $_GET['id'];
   }
else
   {
   $Id = '147';
   }

This works great when I echo $Id However the $Id needs to contain the text from a predetermined table field named $extra1. So I used the code

if (isset($_GET['id']))
   {
   $Id = $_GET['id'];
   }
else
   {
   $Id = '$extra1';
   }

When I now echo $Id it simply says $extra1 - and not the actual content of that field. The field "extra1"will always be a 3 digit number and so when I echo $Id, it should display 222 for example

I hope you guys understand what I'm trying to do and look forward to any help

Thanks

Jason

</div>

Just try with:

if (isset($_GET['id'])) {
   $Id = (int) $_GET['id'];
} else {
   $Id = $extra1;
}

Or even faster:

$Id = isset($_GET['id']) ? (int) $_GET['id'] : $extra1;

change it like this

      $extra1='123' //example 
      if (isset($_GET['id']))
      {
        $Id = $_GET['id'];
      }
      else
      {
        $Id = $extra1;
      }

Try this

$Id = "$extra1";

OR

$Id = $extra1;