0

因此,我通过 mysqli_query 获取值来动态生成报告。这是当前输出 - > http://i.imgur.com/87XWAxQ.png?1我想要的是,当我们为同一个项目回显任务时,项目列只显示一次项目标题并跨越数字该项目下的任务,即TIME MS应该只出现一次

编辑 - 表结构 -

日志(log_id,proj_id,task_id,user_id,小时,日期)

项目(proj_id,标题,描述)

任务(task_id,title,desc,user_id,proj_id)

$q="SELECT proj_id, task_id,SUM(hours),date    
 FROM log
WHERE user_id =$row[0] AND date >= '$s' AND date<= '$e'  
GROUP BY proj_id, task_id";
$res=mysqli_query($con,$q) or die(mysqli_error($con));
while($row=mysqli_fetch_row($res)) /*while rows exist select each row to 
                                     extract and display project name task                                   
                                     name and sometime calc. 

                                    Problem - I wanna display just one cell  
                                     of project name till the tasks under that 
                                     project are displayed. I know this is 
                                     achieved by rowspan but using that here                                       
                                     is skewing up my table */


      {       
         $q="SELECT `title` FROM `projects` WHERE proj_id=$row[0]";
         $res=mysqli_query($con,$q) or die(mysqli_error($con));
         $ptitle=mysqli_fetch_row($res);
         $q= "SELECT title FROM tasks WHERE task_id =$row[1]";
         $res=mysqli_query($con,$q) or die(mysqli_error($con));
         $row=mysqli_fetch_row($res);
         $time=round(($row[2]/$total[0])*100);

         echo '
         <td>'
          .$ptitle[0].    //using rowspan here is skewing up the  table as                                             
                          //  the loop executes seperately for each task    
        '</td>         
          <td>'
          .$row2[0].
        '</td>  
          <td>'
          .$time.
         '</td>
         </tr>';
      }

我知道某处有错误的逻辑,但我就是无法弄清楚。我需要以某种方式检查我们是否仍在显示同一项目的任务并计算编号。任务和集合
<td rowspan='.$count.'>Project Title</td>

4

1 回答 1

0

我无法添加脚本,但我可以告诉你算法

1.First Fetch 行/数组

2.将项目名称保存在PHP全局变量中

3.将下一个结果(标题)与上一个标题进行比较。

if(same) { 使用 javascript 增加行跨度 } else { 在变量中存储新标题 }

注意:- 为此,您必须为表格行设置动态 ID。例子

<?PHP
while(true)
{
$i++;
<tr id="$i"></tr>
}
?>
于 2013-06-13T07:03:32.473 回答