gpt4 book ai didi

php - 在 php 中动态打开 div?

转载 作者:行者123 更新时间:2023-11-28 16:02:57 25 4
gpt4 key购买 nike

请慷慨仁慈。

我有一个 php 元素,我必须在其中显示来自 db 的消息。我已经这样做了,但是要显示 receiver 名称(有点像 gmail),我遇到了这个问题。

我的工作示例代码如下

<style>
#column_1,#column_2 {
width:1200px;
margin: 0 auto

}
#fbCheck {
display:none;
}


#fbCheck:not(:checked) ~ .sidebar-follow-button
{
display:none;
}



#fbCheck:checked ~ .sidebar-follow-button
{
display:block;
z-index : 10;
position: absolute;
background-color: white;
border: 1px solid rgba(0, 0, 0, 0.2);
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
padding: 5px;
}
</style>
<?php
$userList = array('megha','meena','karishma','aadhya','ananya','pooja','mahesh','megha','meena','karishma','aadhya','ananya','pooja','mahesh','megha','meena','karishma','aadhya','ananya','pooja','mahesh','megha','meena','karishma','aadhya','ananya','pooja','mahesh','megha','meena','karishma','aadhya','ananya','pooja','mahesh');
//$sendername = getSenderName($sender_id);
$sendername = 'Admin';

?>
<div id='column_1'>
<div class="header">Sender : <?php echo $sendername;?></div>
<div class="content">
<?php if(count($userList)<2){
echo '<b>Receiver: </b>'.$userList[0].','.$userList[1];

}else{

echo '<b>Receiver: </b>'.$userList[0].','.$userList[1].'...';
?>
<input type="checkbox" id="fbCheck" />
<label for="fbCheck">
&#9660;
</label>
<div class="sidebar-follow-button" style="left: 91px;">
<ul style="width :200px; height:80px; overflow:auto">
<?php
foreach($userList as $name){
echo '<li align="center">'.$name.'</li>';
}
?>
</ul>


</div>
<?php } ?>

</div>

<br>Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree
Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree
</div><br><br>

<?php $userList = array('Bharat','Himanshu','Junaid','Bhavin','Anil');?>
<div id='column_2'>
<div class="header">Sender : <?php echo $sendername;?></div>
<div class="content">
<?php if(count($userList)<2){
echo '<b>Receiver: </b>'.$userList[0].','.$userList[1];

}else{

echo '<b>Receiver: </b>'.$userList[0].','.$userList[1].'...';
?>
<input type="checkbox" id="fbCheck" />
<label for="fbCheck">
&#9660;
</label>
<div class="sidebar-follow-button" style="left: 91px;">
<ul style="width :200px; height:80px; overflow:auto">
<?php
foreach($userList as $name){
echo '<li align="center">'.$name.'</li>';
}
?>
</ul>


</div>
<?php } ?>

</div>

<br>Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree
Your message starts from heree Your message starts from heree Your message starts from heree Your message starts from heree
</div>

我在这里显示了 div 的,但这都是由 php foreach 循环生成的,可能有很多 content_1 div.

它工作正常但是当我点击第二个箭头显示发件人列表时它总是显示第一个消息接收者列表

enter image description here

这个 div 每次都打开,即使我点击第二个箭头或任何如果有超过 2 个

请告诉我如何解决这个问题

感谢任何帮助。提前致谢

最佳答案

你可以这样做:

foreach($record as $data){
if($condition){
$body .= "<div class="open">".$data."</div>";
}else{
$body .= "<div class="closed">".$data."</div>";
}
}
echo $body;

然后创建两个 CSS 样式:

 .open{
display: block;
}
.closed{
display: none;
}

但其他评论是正确的。如果您试图动态更改 php 输出,则需要依赖 ajax 调用。 Ajax 将调用您的 php 文件并返回数据,您可以在不刷新屏幕的情况下向用户显示这些数据。

关于php - 在 php 中动态打开 div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39755181/

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