我有一个PHP错误,这个代码将执行我希望它做的一旦我得到它的工作?

时间:2012-01-26 22:14:18

标签: php html

我的编码有点问题。我正在尝试创建2个下拉菜单。一个用于显示建筑物列表,然后当用户从列表中选择建筑物时,它将显示该建筑物中的房间列表。

问题是我的代码中有错误。以下是代码:

      $sql="SELECT Building, Room FROM Room WHERE Building = '".$building."'";

      $sqlresult = mysql_query($sql);

      $sqldataArray = array();

      while($sqlrow = mysql_fetch_array($sqlresult))
   {
      $sqldataArray[$sqlrow['Building']]; 
      $sqldataArray[$sqlrow['Building']]['Rooms'][$sqlrow['Room']]; 
   }


       $buildingHTML = ""; 
       $buildingHTML .= '<select name="buildings" id="buildingssDrop">'.PHP_EOL;
       $buildingHTML .= '<option value="">Please Select</option>'.PHP_EOL; 

   foreach ($sqldataArray as $building => $buildingData) {      

            $buildingHTML .= "<option value='".$building"'>" . $building . "</option>".PHP_EOL;        

            }
            $buildingHTML .= '</select>';


       $roomHTML = ""; 
       $roomHTML .= '<select name="rooms" id="roomsDrop">'.PHP_EOL;
       $roomHTML .= '<option value="">Please Select</option>'.PHP_EOL;      
            foreach ($buildingData['Rooms'] as $roomId => $roomData) {        

            $roomHTML .= "<option value='".$roomId"'>" . $roomId . "</option>".PHP_EOL;        
  } 

            $roomHTML .= '</select>';

我得到的错误是:

解析错误:语法错误,第363行/web/stud/u0867587/Mobile_app/create_session.php中的意外T_CONSTANT_ENCAPSED_STRING

这是错误的代码行:

 $buildingHTML .= "<option value='".$building"'>" . $building . "</option>".PHP_EOL;  

有没有人知道如何修复此错误,我写的这段代码是否能够执行我所说的我想要下拉菜单执行的内容?

1 个答案:

答案 0 :(得分:0)

变化:

$buildingHTML .= "<option value='".$building"'>" . $building . "</option>".PHP_EOL; 

要:

$buildingHTML .= "<option value='".$building."'>" . $building . "</option>".PHP_EOL; 

并改变:

$roomHTML .= "<option value='".$roomId"'>" . $roomId . "</option>".PHP_EOL;

要:

$roomHTML .= "<option value='".$roomId."'>" . $roomId . "</option>".PHP_EOL;

在串联操作之间使用一致的间距有助于将来更容易发现:

$roomHTML .= "<option value='" . $roomId . "'>" . $roomId . "</option>" . PHP_EOL;