【问题标题】:Explode reply after group concat组连接后爆炸回复
【发布时间】:2013-10-30 21:25:23
【问题描述】:

我设法从回复表中获得回复的唯一方法是通过组 concat,但所有回复都出现在一行中。我需要每行显示每个回复。在 mysql 查询之后,我尝试以各种方式对其进行爆炸。我发现的大多数爆炸代码仅适用于 echo 而不适用于一行。他们是一种爆炸​​方式还是另一种分离回复的方式。基本上,一旦我将对帖子/图像的回复分组,只会出现一个回复,但是当我将所有回复分组连接时,只会出现一行。我已经设法用空格或逗号分隔它们,但它们仍然保持在一行中。

<?php  


   $sql = "     
 SELECT images.mid, images.id, images.who, header.username, images.message, images.name, GROUP_CONCAT(reply.reply
 SEPARATOR 0x1E ) as heat
FROM header, images
LEFT JOIN reply ON reply.reply = reply.mid
 OR reply.mid = images.mid
WHERE images.name IS NOT NULL = header.id
AND images.who IS NOT NULL 
AND images.message IS NOT NULL 
GROUP BY images.mid
";

$rs = mysql_query( $sql );

 while ( $row = mysql_fetch_array( $rs )

  ) {



   $name = $row['name'];

    $mid = $row['mid'];
   $title = $row['title'];
   $who = $row['who'];
$details = $row['details'];
$message = $row['message'];
$id = $row['id'];
    $heat = explode(',', $row['heat']);
  $heat = array (".",$row['heat']);
   foreach($heat as $heat)



 $row=mysql_fetch_array($rs);

  if($row){
            $name= $row['name'];


  ?>

   <td>

        <table>

                 <tr>
               <td>
   <a href="a/<?=$name ?>" rel='lightbox' title='$timestamp - $message'> <img src=     "a/<?=$name ?>" width='150' height='100'" >  </a>  </td> 
                     </tr>



                    <tr> <td> <?=$row['name'] ?> 
                     </td> </tr>

                      <tr>
  <td>    <?=$row['who'] ?> </td> </tr>
                     <tr>
  <td> <?=$row['message'] ?></td> </tr>
                    <tr>
   <td>   <?=$row['id'] ?></td> </tr>
                      <tr>
<td>   <?=$row['mid'] ?> </td> </tr>
                        <tr>
  <td>   <?=$row['username'] ?></td>
                </tr><tr>
 <td>  <?=$row['heat'] ?></td>  


                   </tr>  

       </table>

    </td>
 <?
}
        else{
            echo "<td>&nbsp;</td>"; //If there are no more records at the end, add a blank column
        }

} while($row);
echo "</table>";


  ?>


    </div>

    </body>
  </html>

这是我通过组 concat 得到的回复的结果。

   She fell, she ate, she came, its good, okay.

我也设法把它变成了一个数组,但我也被困住了。 对于那些了解 CSS 的人。他们是一种将数据数组放入行的方法。我记得看到过,但不记得怎么做。

【问题讨论】:

  • 您必须再次遍历回复列表并为每个回复打印一个新行。看起来您正在尝试这样做,但在内部循环中第二次使用mysql_fetch_array?为什么?
  • 但您不希望它们都连续出现,对吗?也许我误解了你的问题。这个缩进很难读
  • 你知道的。我认为你确实有一点。为什么我有两个循环数组。也许这就是问题所在。
  • 感谢 Eevee,您在一个非常复杂的代码中指出了一些好的东西,一些人也有答案。我现在得到了不同的结果,不包括那个额外的循环数组,现在必须弄清楚如何正确地分解。

标签: javascript php html mysql css


【解决方案1】:

关闭循环:您在内部循环中第二次调用mysql_fetch_array 并引用$row['heat'],而不是使用您已经拥有并拆分的$heat。删除第二个提取并使用$heat。 :)

【讨论】:

  • 这不是答案。这是爆炸的唯一方法,或者您可能会说从组 concat 爆炸数组时会得到的唯一结果
猜你喜欢
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多