gpt4 book ai didi

php - 属性内的 If else 语句和 If else 语句内的属性

转载 作者:行者123 更新时间:2023-11-28 04:43:33 28 4
gpt4 key购买 nike

我正在处理一个标签,我可以在其中拥有一个具有数据映射突出显示的链接图像,我如何才能使 if else 语句在属性中起作用?并在声明中包含另一个属性。

这是我的代码:

<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 } ?>

最佳答案

使用三元运算符比使用 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 } ?>

关于php - 属性内的 If else 语句和 If else 语句内的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41083177/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com