如何显示课程总数?

时间:2019-07-03 15:42:50

标签: php

我正在使用核心php开发网站。所以在网站上有一些类别,我在其中添加课程,我想显示课程数,例如dis 参考链接:-https://stageserver.co/ppcl/courses.php(请选中“浏览所有类别”部分)

我已经创建了函数(function.php):

function get_count_course(){
    global $dbh;
    $getregcourse = "SELECT * FROM courses 
                    WHERE course_cat_id = :id 
                    ORDER BY date_added DESC";

    $setregCourse = $dbh->prepare($getregcourse);
    $setregCourse->bindParam(':id', $id);

    $setregCourse->execute();

    $courses = $setregCourse->fetchAll();

    return $courses;
}

,并希望显示在template(courses.php)中:-

<section class="ppcl__allbrowser">
    <div class="wrp-box">
        <h3 class="ppcl__educenterheading ppcl--colorblack">
            Browse All Categories
        </h3>
        <div class="ppcl__allbrowsercolunm">
<?php
$category = get_course_categories();
$Courses=get_count_course();

foreach ($category as $key => $value) {
?>
            <div class="ppcl__allbrowser--item">
                <a href="" class="ppcl__allbrowser-name <?php echo ($key == 0 ? 
'course_active':'');?>" data-evalz="<?php echo $value['course_cat_id'];?>" 
id="category_<?php echo $value['course_cat_id'];?>"  > <?php echo $value['course_cat_name']; ?></a>

                    <div class="bredge border-left">
                        <div class="number">
                            <span><?php echo count($Courses); ?></span>
                    </div>
                    <p class="courses-bredgetitle">Courses</p>
                </div>
            </div>
<?php       
}
?>

        </div>
    </div>
</section>

0 个答案:

没有答案