Dymically在PHP中打开div?
问题描述:
请在此表示慷慨和善意。Dymically在PHP中打开div?
我有一个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">
▼
</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">
▼
</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's
这里,但所有这一切是由PHP foreach
回路中产生,并可能有很多content_1
div
。
它工作正常,但是当我在第二个箭头点击显示发件人列表它显示我的第一个消息接收器列表
这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文件并返回你可以显示给用户的数据,而不用刷新屏幕。
+0
如何解释点击事件? CSS是否添加行为或对事件做出反应?他的名单中的所有其他用户名会发生什么情况?为您的努力提供赞成票,但不提供切实可行的解决方案.... – Poiz
您使用Ajax吗? – Poiz
没有PHP和CSS只有 – user1234
我通过在db行中循环生成此代码 – user1234