如何在mysql中获取id

this is showing all floors of building and i want to show selected building floors how can i do this i use this link floors.php?id=Building1 but its is not working please help me

if i write in there building1 it is working fine where buildingname='building1'

if i use this one where buildingname='$id' it is not working

how can i use like this

floors.php?id=Building1

if i enter this link then it will show all selected building result

<?php
    $max_results = 8;

    $from = (($page * $max_results) - $max_results);


    if(empty($_POST)) {
                  $query = "SELECT * FROM floors  where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
    } 
    $result = mysql_query("SET NAMES utf8"); //the main trick
    $result = mysql_query($query) or die(mysql_error());
    $rows = mysql_num_rows($result);

    $count=0;
    while($row = mysql_fetch_array($result))
        {
            if($count%4==0)
            {
            echo "<tr/>";
            echo "<tr>";
            }

            echo "<td><div align='center'><img src='images/floor.gif' width='60' height='90'></a><p>" . $row['floorno'] . "</p><div></td>";

            $count++;


    }



    echo "</tr>";
    echo "</table>"; 
    echo '</div>';
    ?>
if(empty($_POST)) {
    $query = "SELECT * FROM floors  where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
} 

the right is:

if (isset($_GET['id'])) {
    $id = filter_input(INPUT_GET, 'id');
    $query = "SELECT * FROM floors  where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
} 

that may help you.

<?php
   $id =isset($_GET['id'])?$_GET['id']:null; // here you put value in $id only if it has some value.
   $max_results = 8;

   $from = (($page * $max_results) - $max_results);


   if($id != null) {
      $query = sprintf("SELECT * FROM floors WHERE buildingname='%s' ORDER BY floorno ASC LIMIT $from, $max_results", mysql_real_escape_string($id)); // safe from sql injection
      $result = mysql_query("SET NAMES utf8"); //the main trick
      $result = mysql_query($query) or die(mysql_error());
      $rows = mysql_num_rows($result);


      $count=0;
      while($row = mysql_fetch_array($result))
      {
        if($count%4==0)
        {
        echo "<tr/>";
        echo "<tr>";
        }

        echo "<td><div align='center'><img src='images/floor.gif' width='60' height='90'></a><p>" . $row['floorno'] . "</p><div></td>";

        $count++;
      }
   }


   echo "</tr>";
   echo "</table>"; 
   echo '</div>';
?>