签入数组值

bxgwgixi  于 2021-06-23  发布在  Mysql
关注(0)|答案(1)|浏览(212)


上面的图片是我想实现的,唯一的问题是我在回显主题和主题下的主题,但我只想回显说英语和英语下的所有主题将在英语下。但我知道每个主题都有自己的主题。因此,从图像两个英文下拉菜单。这是密码。

<?php
    $sql = "SELECT note_id, class, subject, topic, content, author FROM notes WHERE class = 'JHS 2'";
    $result = $pdo->query($sql);
    $result->setFetchMode(PDO::FETCH_ASSOC);
    while($row=$result->fetch()){
        if(!in_array('subject', $row['subject']){
?>
<li><a class="collapsible-header waves-effect arrow-r"><i class="fa fa-chevron-right"></i><?php echo $row['subject']?><i class="fa fa-angle-down rotate-icon"></i></a>
<div class="collapsible-body">
<ul class="list-unstyled">
    <li><a data-id="<?php echo $row['note_id']?>" href="<?php echo $row['note_id']?>" class="waves-effect" id="getUser"><?php echo $row['topic']?></a>
    </li>
</ul>
</div>
</li>
<?php
        } else {
            echo ""
        }
    }

?>
pieyvz9o

pieyvz9o1#

这应该输出主题和主题,并允许每个主题有多个主题。另外,else中的echo“”是不需要的。

<?php
    $sql = "SELECT note_id, class, subject, topic, content, author FROM notes WHERE class = 'JHS 2' ORDER BY subject, topic";
    $result = $pdo->query($sql);
    $result->setFetchMode(PDO::FETCH_ASSOC);
    $lastSubject = '';
    while($row=$result->fetch()){
        if(!in_array('subject', $row['subject']) {
            if($lastSubject != $row['subject']) {
?>
<li><a class="collapsible-header waves-effect arrow-r"><i class="fa fa-chevron-right"></i><?php echo $row['subject']?><i class="fa fa-angle-down rotate-icon"></i></a>
<div class="collapsible-body">
<?php
            }
?>
<ul class="list-unstyled">
    <li><a data-id="<?php echo $row['note_id']?>" href="<?php echo $row['note_id']?>" class="waves-effect" id="getUser"><?php echo $row['topic']?></a>
    </li>
</ul>
<?php
            if($lastSubject != $row['subject']) {
?>
</div>
<?php
                $lastSubject = $row['subject'];
            }
?>
</li>
<?php
        }
    }

?>

相关问题