首页 > 解决方案 > 如何在codeigniter的td列中显示静态值

问题描述

大家好,我有一张桌子,我需要显示课程报告,所以每门课程都有一个阶段,所以我有 16 种阶段,例如:暂停、资产不完整、SME 讨论..等等。就像我有 16 种类型所以我想在 mt td 列中显示 16 种类型

<table  class="table table-bordered">
                            <thead>
                                <tr><th class="center">#</th>
                                    <th class="center"><a href="ProjectView.php?course_id=1">PHY</a></th>
                                    <th class="center"><a href="ProjectView.php?course_id=2">CHE</a></th>
                                    <th class="center"><a href="ProjectView.php?course_id=3">ZOO</a></th>
                                    <th class="center"><a href="ProjectView.php?course_id=4">BOT</a></th>
                                    <th class="center"><a href="ProjectView.php?course_id=5">MATH</a></th>
                                    <th class="center">Total</th>
                                </TR>
                            </thead>
                            <tbody>
                                <tr>
                                    <td>On Hold</td>
                                    <td>0</td>
                                    <td>0</td>
                                    <td>0</td>
                                    <td>0</td>
                                    <td>0</td>
                                </tr>
                            </tbody>
                        </table>

剩余的 td 我必须计算每门课程的数量并显示

谁能帮助我我该怎么做。

提前致谢。

标签: phpcodeigniter

解决方案


如果要将变量从控制器传递到视图,请在 $data 变量中进行。

//Controller
$this->load->model('mymodel);
$data['var1'] = "Some value";
$data['var2'] = "Some value";
$data['query'] = $this->mymodel->thefunction();

//Model = mymodel
//function = thefunction(), you have to obviously create the class and function, if you don't know how to do that, let me know
$sql = "SELECT Count(courseid) as 'statusCount'";
$query = $this->db->query($sql);

当您现在要在视图模板中显示这些变量时,请按变量的名称调用变量,而不使用“$data 部分”

//In your view
<?php
 foreach($query->result() as $row) {
   echo "<td>" . $row->statusCount . "</td>";
 }
?>


推荐阅读