获取mysql结果的下一行,以比较当前行与当前行的索引是否相同->循环输出


Fetching next row of mysql result to compare an index with present row which if being same -> loop output

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

edit - Table Structure -

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

项目( proj_id ,标题,desc)

任务( task_id ,标题,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>

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

1。首先获取行数/数组

2。将项目标题保存在PHP全局变量

3。比较下一个结果(标题)与前一个标题。

如果(相同){使用javascript增加rowspan}其他的{将新标题存储在变量中}

注意:-要做到这一点,你必须为表行设置动态id。示例

<?PHP
while(true)
{
$i++;
<tr id="$i"></tr>
}
?>