[来自数据库的mysql下拉菜单项

问题描述 投票:0回答:1

我正在使用一个下拉菜单,该菜单项是来自称为通知的表的行,每一行都有一个类型列,并且每种类型都有一个特定的输出(echo),以便将每行作为我循环的菜单中的一项输出MySQL数组中的每个项目,但是当我执行时,这些项目显示在下拉菜单中,但它们是空的,如下所示:-

ScreenShot

代码:-

// notifications function here //
// unreaded notifications count to echo in the bootstrap4 badge //
$unreadednotifications = "SELECT * from `notifications` where `status` = 'unread' order by `date` DESC";
$unreadedcount = count(fetchAll($unreadednotifications));
// all notifications to sort in the dropdown menu //
$notifications = "SELECT * FROM `notifications` WHERE accountid = '8' ORDER BY `date` DESC";
$notificationscount = count(fetchAll($notifications));

// notification function ends here//



<li class="nav-item dropdown">
                    <a class="nav-link" href="#" id="notificationsdrop" onclick="badgefade()" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                    <div style="font-size: 12px;"><i class="fa fa-bell fa-3x bell" aria-hidden="true"></i><?if($unreadedcount > 0){echo'<span class="badge badge-notify" id="notificationsBadge" style="font-size:15px;">'.$unreadedcount.'</span>';}?></div></a>
                <div class="dropdown-menu notifications" aria-labelledby="notificationsdrop">
                    <? if(count(fetchAll($notifications)) > 0){
                        foreach(fetchAll($notifications) as $i){
                    ?>
                    <a class="dropdown-item" href="view.php?id=<?php echo $i['id'] ?>" style="<? if($i['status']==['unread']){
                        echo"font-weight:bold;";
                    }?>">
                    <?
                    if ($i['type']==['socialalert']){
                        echo'Someone Followed You';
                    }
                    ?>
                    </a>
                    <?}}?>
                </div>
            </li>

更新:添加了function.php:-

    function fetchAll($query){
        $con = new PDO(DBINFO, DBUSER, DBPASS);
        $stmt = $con->query($query);
        return $stmt->fetchAll();
    }
    function performQuery($query){
        $con = new PDO(DBINFO, DBUSER, DBPASS);
        $stmt = $con->prepare($query);
        if($stmt->execute()){
            return true;
        }else{
            return false;
        }
    }

?>
php mysql twitter-bootstrap pdo
1个回答
0
投票

固定:我忘记了if语句的相等值必须是这样。

if ($i['type']=='socialalert'){
     echo'Someone Followed You';
}

© www.soinside.com 2019 - 2024. All rights reserved.