2016-12-11 51 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,映射消失 –