2016-03-10 46 views
0

如何更改MATERIALIZE CSS中SELECT標記的值。我試圖顯示從數據庫存儲的選定項目。我試着在select的末尾添加.material_select(),但它只檢索行中的最後一個。我如何顯示每一個嘗試?這是迄今爲止我嘗試過的。而不是只得到物化選擇中的最後一行

$(function() { 

    <?php 
    $q = $db->query("SELECT buildingID, buildingName,building_projectID, floorNumber FROM tblBuilding"); 
     while($r = $q->fetch(PDO::FETCH_ASSOC)){ 
      $buildingID = $r['buildingID']; 
      $buildingName = $r['buildingName']; 
      $building_projectID = $r['building_projectID']; 
      $floorNumber = $r['floorNumber']; 
     $t = $db->query("select projectName from tblProject where projectID = $building_projectID "); 
     while($u = $t->fetch(PDO::FETCH_ASSOC)){ 
      $projectName = $u['projectName']; 

    ?> 
      $("#editModal<?php echo $buildingID ?>").click(function(){ 
       alert('<?php echo $projectName ?>'); 
       $("#editBuildingName").val("<?php echo $r['buildingName'] ?>"); 
       $("#editBuildingProject").val("<?php echo $projectName");    
       $("#editBuildingFloors").val("<?php echo $floorNumber ?>"); 


      }); 
<?php }}?> 
}); 
+0

你能告訴你的HTML以及?您是否嘗試過'$('select')。material_select('destroy');'然後'$('select')。material_select();'在更新值之後? – Michael

回答

1

$("#editBuildingProject").val("<?php echo $projectName");

使用本:

$("#editBuildingProject").val("<?php echo $building_projectID ?>").material_select('update');