dongwu8064 2014-03-07 00:50
浏览 8
已采纳

在php-mysql中,如何在结果表的单元格中结合sql查询的结果?

I am making the code of PHP-MySQL. But I gain have the 2 and more as the result of the left join in the MySQL. So I want to union the results in a cell of the result table as the captured picture.

enter image description here

Here is my real captured picture in my computer.

My php code is as like below.

$result = mysqli_query($con,$sql);


 while($row = mysqli_fetch_array($result))
 { 

 echo "<table border='1' style='background:#dddddd;border-color:green;'>";
 echo "<h2><p >진료과 (Subject) : ".$row['subject']."</p></h2>";
   echo "<tr>";

 echo "<th >"."<form action='search1.php' method='get'>"."<button type='submit' 

  name='code' value='".$row['code']."'>Code</th>";
  echo "<th ><a href='".$row['ds_url']."'>"."한국병명</a></th>";
  echo "<th ><a href='".$row['ds_url']."'>"."Disease name(En.)</a></th>";
  echo "<th >"."<form action='search1.php' method='get'>"."<button type='submit' 

  name='code' value='".$row['family']."'>"." Family History</button> </th>";

 echo "</tr>";
  echo "<tr>";
  echo "<td >" . $row['code'] . "</td>";
  echo "<td >" .$row['disease_co']."</td>";
  echo "<td >" .$row['disease_en']."</td>";
 echo "<td >" .$row['family']."</td>";
    echo "</tr>";
  ---

 echo "<tr>";
  echo "<th>소아과</th>";
  echo "<th>내과</th>";
  echo "<th>산과</th>";
  echo "<th>정형외과</th>";

   echo "</tr>";

 echo "<tr>";
  echo "<td>".$row['ped_content']."</td>";
  echo "<td>".$row['im_content']."</td>";
  echo "<td>".$row['ob_content']."</td>";
  echo "<td>".$row['os_content']."</td>";

   echo "</tr>";

   ----

  echo "</table>";
  }

The While phrase in the above php code is just 1, but the number of the result table depend on the number of im_content.

So, I want to union the result of im_content in a cell as the above captured picture. But, I am short of ability. Please give me a piece of advice. Thank you for your concern.

My sql query sentence is as like below.

  SELECT code_en.code, code_co.disease_co, code_en.disease_en , hx.family, 

  hx.personal, note.note, inclusion.inclusion, exclusion.exclusion, ds.ds_content, 

   ------

  subject.icd_category, subject.group_code, im.im_content
  FROM code_en
  LEFT JOIN subject ON code_en.code = subject.code
  LEFT JOIN note ON code_en.code = note.code
  -------
  left join im on code_en.code = im.code
  WHERE code_en.code = '".$code."'"

Thank you, Barmar!

  • 写回答

1条回答 默认 最新

  • dongrou2920 2014-03-07 01:41
    关注

    I'm not totally sure I understand the question, but I think this is what you want:

      SELECT code_en.code, code_co.disease_co, code_en.disease_en , hx.family, 
    
      hx.personal, note.note, inclusion.inclusion, exclusion.exclusion, ds.ds_content, 
    
       ------
    
      subject.icd_category, subject.group_code, GROUP_CONCAT(im.im_content) AS im_content
      FROM code_en
      LEFT JOIN subject ON code_en.code = subject.code
      LEFT JOIN note ON code_en.code = note.code
      -------
      left join im on code_en.code = im.code
      WHERE code_en.code = '".$code."'"
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛