2016-12-11 77 views
0

我正在一個標籤,我可以有一個鏈接的圖像,有一個數據映射 - 突出顯示,我怎麼做,如果其他語句工作內屬性?在聲明上將包含另一個屬性。如果其他語句裏面的屬性和一個屬性如果其他語句

這裏是我的代碼:

<map id="ground" name="ground"> 
    <?php 

    $sql = "SELECT * FROM stall s 
    LEFT JOIN tenant t 
    ON t.stall_id = s.stall_id 
    LEFT JOIN rent r 
    ON r.tenant_id = t.tenant_id 
    AND r.rent_status = 1 
    WHERE s.stall_id = 1";   

    $query = $conn->prepare($sql); 
    $query->execute(); 
    $fetch = $query->fetchAll(); 

    foreach ($fetch as $key => $value) { ?> 
    <area id="9" shape="rect" coords="9,98,46,117" data-toggle="modal" class = "stallstyle1" 
    href="#stall_modal9" 
    value="<?php echo $value['rent_status']?>" 
    <?php 
    if ($value ['rent_status'] == 1) { 
    data-maphilight='{"strokeColor":"008000","strokeWidth":3,"fillColor":"7CFC00","fillOpacity":0.6,"alwaysOn":true}'> 
    } else { 
    data-maphilight='{"strokeColor":"FF0000","strokeWidth":3,"fillColor":"FF3333","fillOpacity":0.6,"alwaysOn":true}'> 
    } 
    ?> 

<?php } ?> 

回答

0

使用三元運算符是比較容易的和可以理解的,而不是使用的if/else。因此,使用三元運算符來獲取屬性data-maphilight的值,然後在標籤中使用它。希望如果您從數據庫中獲取值,以下代碼將起作用。

<map id="ground" name="ground"> 
    <?php 

    $sql = "SELECT * FROM stall s 
    LEFT JOIN tenant t 
    ON t.stall_id = s.stall_id 
    LEFT JOIN rent r 
    ON r.tenant_id = t.tenant_id 
    AND r.rent_status = 1 
    WHERE s.stall_id = 1";   

    $query = $conn->prepare($sql); 
    $query->execute(); 
    $fetch = $query->fetchAll(); 

    foreach ($fetch as $key => $value){ 

    $maphilight= ($value['rent_status'] == 1)?'{"strokeColor":"008000","strokeWidth":3,"fillColor":"7CFC00","fillOpacity":0.6,"alwaysOn":true}':'{"strokeColor":"FF0000","strokeWidth":3,"fillColor":"FF3333","fillOpacity":0.6,"alwaysOn":true}'; 
    ?> 
    <area id="9" shape="rect" coords="9,98,46,117" data-toggle="modal" class = "stallstyle1" 
    href="#stall_modal9" value="<?php echo $value['rent_status'];?>" data-maphilight='<?php echo $maphilight;?>'> 
<?php } ?> 
+0

顏色仍然沒有變化。 –

+0

$ value ['rent_status']的值是多少? –

+0

rent_status的值爲1,如果我將其更改爲0,映射消失 –