dongnai2804 2015-06-03 08:01
浏览 54
已采纳

在各种单元格中显示数组值

I want to display the name and date for specific requirements. for eg requirement oracle DBA has 3 submittal on various dates.table 'requirement' have field as e_id and req_id.

2nd table 'submittal' has req_id, submittal and date fields I want to display submittal in one column and date in another column based on requirement.

enter image description here

I tried to display with array values

 $sub="select a.*,b.c_name from requirement as a,client as b where a.c_id=b.c_id and e_id='2'";
 $sub1=mysql_query($sub);

 while($sfet=mysql_fetch_assoc($sub1))
 {
     echo '<tr>';
     $req_id=$sfet['req_id'];
     echo '<td>'.$sfet['c_name'].'</td>';
     echo '<td>'.$sfet['title'].'</td>';
     $was="select * from resume where req_id='$req_id'";
     $was1=mysql_query($was);

     while($wfet=mysql_fetch_assoc($was1))
     {
         $array[] = $wfet;
     }

     echo '<td>';
     echo $array[]['username'];
     echo '</td>';

     echo '<td>';
     echo $array[]['date'];
     echo '</td>';
     echo '</tr>';
}
  • 写回答

1条回答 默认 最新

  • dsjmrpym220113739 2015-06-03 08:58
    关注

    change your code as follows:

    while($sfet=mysql_fetch_assoc($sub1))
    {
         echo '<tr>';
         $req_id=$sfet['req_id'];
         echo '<td>'.$sfet['c_name'].'</td>';
         echo '<td>'.$sfet['title'].'</td>';
         $was="select * from resume where req_id='$req_id'";
         $was1=mysql_query($was);
    
         $username = $date = [];
         while($wfet=mysql_fetch_assoc($was1))
         {
             $username[] = $wfet['username'];
             $date[] = $wfet['date'];
         }
    
         echo '<td>';
         echo implode('<br>',$username);
         echo '</td>';
    
         echo '<td>';
         echo implode('<br>',$date);
         echo '</td>';
         echo '</tr>';
    }
    

    EDIT: even better solution would be to use GROUP_CONCAT as follows:

    $sub = "SELECT a.*, b.c_name, 
            GROUP_CONCAT(c.username ORDER BY c.date SEPARATOR '<br>') AS g_username,
            GROUP_CONCAT(c.date ORDER BY c.date SEPARATOR '<br>') AS g_date 
        FROM requirement as a 
        JOIN client as b ON a.c_id=b.c_id 
        JOIN resume c ON a.req_id=c.req_id GROUP BY a.req_id";
    
    $sub1=mysql_query($sub);
    while($sfet=mysql_fetch_assoc($sub1))
    {
        echo '<tr>';
        $req_id=$sfet['req_id'];
        echo '<td>'.$sfet['c_name'].'</td>';
        echo '<td>'.$sfet['title'].'</td>';
        echo '<td>'.$sfet['g_username'].'</td>';
        echo '<td>'.$sfet['g_date'].'</td>';
        echo '</tr>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 GD32 SPI通信时我从机原样返回收到的数据怎么弄?
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题