使td值在codeigniter中显示为静态 [英] get td values display as static in codeigniter

查看:44
本文介绍了使td值在codeigniter中显示为静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试将第一个td值显示为静态,所以我将这些值保留在一个数组中,我尝试增加这些值并尝试显示,但是当我得到它时,如果我有,它将根据foreach值进行显示在foreach中有一条记录显示一个值,如果我有2条记录,则显示两个值.

Hi guys i am trying to display the first td values as static so i have keep those values in one array and i try to increase the values and try to display but when i get it is displaying depending on foreach values if i have one record in foreach it is displaying one value and if i have 2 records it is displaying 2 values.

但是如果我在foreach中也有值,我想显示所有td值.

But i want to display all td value if i have values in foreach or not also.

这是我的代码:

 <tbody>
                                <?php
                              $arr = array(0=>'On Hold',1=>'Asset Incomplete',2=>'SME Discussion',3=>'a',4=>'b',5=>'c',6=>'d',7=>'e',8=>'f',9=>'g',10=>'h');
                              $i = 0;
                                foreach($getCourse as $report)
                                  $status= $report->status;
                                  {
                                    ?>
                                  <tr>
                                      <td><?php echo $arr[$i]; ?>
                                      <?php $i++;  ?></td>
                                    <td><?php
                                                 if($status==1)
                                                 {
                                                    echo "On Hold"; 
                                                 }
                                                 elseif($status==2)
                                                 {
                                                     echo "Asset Incomplete";
                                                 }
                                                 elseif($status==3)
                                                 {
                                                     echo "Yet to Start";
                                                 }
                                                 elseif($status==4)
                                                 {
                                                     echo "SME Discussion";
                                                 }
                                                 elseif($status==5)
                                                 {
                                                     echo "Development";
                                                 }
                                                 elseif($status==6)
                                                 {
                                                     echo "PB Review";
                                                 }
                                                 elseif($status==7)
                                                 {
                                                     echo "PB Fixes";
                                                 }
                                                 elseif($status==8)
                                                 {
                                                     echo "PB2 Review";
                                                 }
                                                 elseif($status==9)
                                                 {
                                                     echo "PB2 Fixes";
                                                 }
                                                 elseif($status==10)
                                                 {
                                                     echo "Alpha Development";
                                                 }
                                                 elseif($status==11)
                                                 {
                                                     echo "Alpha Review";
                                                 }
                                                 elseif($status==12)
                                                 {
                                                     echo "Alpha Fixes";
                                                 }

                                                 elseif($status==13)
                                                 {
                                                     echo "Beta Review";
                                                 }
                                                 elseif($status==14)
                                                 {
                                                     echo "Beta Fixes";
                                                 }
                                                 elseif($status==15)
                                                 {
                                                     echo "Gamma";
                                                 }

                                               ?></td>
                                    <td><?php echo $report->coursename; ?></td>
                                    <td><?php echo $report->statuscount;?></td>
                                    <td></td>
                                </tr>
                               <?php
                                }
                                ?>
                            </tbody>

这是我的控制人:

public function index()
{
        if ($this->session->userdata('is_logged')) {
        $data['getCourse']=$this->Report_model->getTopicReports();
    $this->load->view('template/header');
        $this->load->view('reports/report',$data);
        $this->load->view('template/footer');
}
    else {
        redirect("Login");
    }
}

这是我的模特:

public function getTopicReports()
{
     $this->db->select('count(t.status) as statuscount,t.topicName as topicname,c.coursename,t.status')
     ->from('topics t')
     ->join('course c', 't.courseId = c.id')
     ->where('t.courseid',1)
     ->where('t.status',5);
     $query = $this->db->get();
     return $query->result();
}

这是我要在此处显示的参考图像:

This is how i want to display here is my referrence image:

任何人都可以提前帮助我该怎么做.

Can anyone help me how to do that thanks in advance.

推荐答案

最终更新&工作版本

对我来说,这很棘手.原来这是我觉得很尴尬的索引编制问题.

For me this was tricky. This turned out to be what I felt to be a awkward indexing issue.

问题是您的数据不能很好地优化以适应您要执行的任务.遍历表格时,您必须进行奇怪的比较.我能够完成它.

The problem is that your data is not optimized very well to accommodate the task you are asking for. You have to make odd comparisons as you traverse the table. I was able to get it accomplished.

我实际上对看到一种更精致的方法非常感兴趣.但是在此之前,此代码将动态生成一个表,该表与您在问题中发布的示例图片的输出匹配.

I would actually be very interested in seeing a more refined approach. But until that happens this code will dynamically generate a table that matches the output of the sample pictures that you posted in your question.

我已经用一些示例数据测试了此代码,这些示例数据与您在注释中发布的数组结构相匹配.

I have tested this code with some sample data that matches the array structure that you posted in your comments.

这是代码:

//Create an array with your status values.
$rowName = array(

  'On Hold',
  'Asset Incomplete',
  'Yet to Start',
  'SME Discussion',
  'Development',
  'PB Review',
  'PB Fixes',
  'PB2 Review',
  'PB2 Fixes',
  'Alpha Development',
  'Alpha Review',
  'Alpha Fixes',
  'Beta Review',
  'Beta Fixes',
  'Gamma'

);

//Generate a list of class names and get rid of any duplicates.
foreach($getCourse as $report){

  $courseNames[] = $report->coursename;

}

$courseNames = array_unique($courseNames);


//Create the header.
echo
'<table>
  <thead>
    <tr>
      <th>#</th>';

      foreach($courseNames as $course){

        echo '<th>' . $course . '</td>';

      }

    echo
      '<th>Total</th>
    </tr>
  </thead>

<tbody>';

  //Iterate across the array(list) of status values.
  for($i = 0; $i < count($rowName); $i++){

    echo
    '<tr>';

        echo '<td>' . $rowName[$i] . '</td>';

        //Iterate through all combinations of class names and status values.
        for($j = 0; $j < count($courseNames); $j++){

          //Set flags and intial values.
          $found = FALSE;
          $total = 0;
          $value = NULL;

          for($k = 0; $k < count($getCourse); $k++){

            //***Note - The ""$getCourse[$k]->status - 1" is because the status values in your data do not appear
            //to start with an index  of 0.  Had to adjust for that.

            //Sum up all the values for matching status values.
            if(($getCourse[$k]->status - 1) == $i){

              $total += $getCourse[$k]->statuscount;

            }

            //Here we are checking that status row and the status value match and that the class names match.
            //If they do we set some values and generate a table cell value.
            if(($getCourse[$k]->status - 1) == $i && $courseNames[$j] == $getCourse[$k]->coursename){

              //Set flags and values for later.
              $found = TRUE;
              $value = $k;

            }

          }

          //Use flags and values to generate your data onto the table.
          if($found){

            echo '<td>' . $getCourse[$value]->statuscount . '</td>';

          }else{

            echo '<td>' . '0' . '</td>';

          }

        }

        echo '<td>' . $total . '</td>';

   echo
   '</tr>';

  }

echo '</tbody>
</table>';

这篇关于使td值在codeigniter中显示为静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆