drgc9632 2015-07-15 06:51
浏览 17

使用数据库值创建表列名

I should be write report page with php.this report include one table that get information from database. my structure like that:

  technician_id     psp_id   percent  pm_date

 -------------     ------- --------  --------

       8             16        50    13940415
       10            16        40    13940416
       12            16        60    13940417

I want show table like :

   technician_name  13940415   13940416   13940417 

   --------------   --------   --------   ---------

         ali           16         00         00
        abbas          00         40         00
        ahmad          00         00         60

I need help soon.thanks

  • 写回答

1条回答 默认 最新

  • drnf09037160 2015-07-15 10:11
    关注

    my code:

    echo "<table border='1'>";
    echo"<tr>";
    echo"<td></td>";
    $date_value = mysql_query("select  pmcontrol.* from pmcontrol")or  die(mysql_error());
    $count=mysql_num_rows($date_value);
    
                            while($rows=mysql_fetch_array($date_value)){
                             $arr = array();
                            echo"<td>".$rows['pmdate']."</td>";
                            for($k=0;$k<31 ;$k++){
    
                            $arr[$k]=$rows['pmdate'];
                              }
                             }
                             echo"</tr>";   
                             $search=mysql_query("select pmcontrol.*,user.*  
    
                             from        pmcontrol
                             INNER JOIN  user
                             on          user.u_id=pmcontrol.technician_id
                             INNER JOIN  psp
                             on          psp.id=pmcontrol.psp_id
                             where       pmcontrol.pmdate between $from_date and $until_date
                             group by    technician_id
    
                          ") or die(mysql_error());
       $count=mysql_num_rows($search);
    
       while($row=mysql_fetch_array($search)){
       echo"<tr>"; 
       echo"<td>".$row['user_name']."  ".$row['user_family']."</td>";
       for($k=0;$k<2;$k++){
       if($row['pmdate']=$arr[$k]){
       echo"<td>".$row['percent']."</td>";
       }
       else if($row['pmdate']!=$arr[$k]) {
    
       echo"<td>00</td>";   
       }}
       echo"</tr>";
        }
    
       echo "</table>";
    

    my result :

      technician_name     13940415  13940416  13940417
      ---------------     --------  --------  --------
    
             ali             16        16        16
             abbas           40        40        40
             ahmad           60        60        60
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题