首页 > 解决方案 > 在正确位置的 roomlist() 中显示 activechatusers()

问题描述

我正在编写一些爱好 PHP 聊天室项目,但我卡住了,在房间列表中的正确位置显示活动的房间用户列表。用户列表应该显示在某个表内的文本流中,但是当我尝试通过 PHP 中的函数调用将其显示在想要的位置时,PHP 会忽略该位置并在显示 while() 之前或之后显示预格式化的 SQL 输出。 .

我怎样才能在另一个while()中显示这个while(),或者至少是它想要的Textoutput?

看看 (2) 应该在哪里显示用户,以及 (1) 在哪里显示它! (截屏)

这是我的代码:

while($c >0){

   
echo '<table style="border-collapse: collapse; width: 100%;" border="1">
  <tbody>
    <tr>
      <td style="width: 100%;"><RoomHeading>'.$Roomname[$c].'</RoomHeading></td>
    </tr>
  </tbody>
</table>
<table style="border-collapse: collapse; width: 100%;" border="1">
  <tbody>
    <tr>
      <td style="width: 50%;"><img src="Bild.jpg"></td>
      <td style="width: 50%;"><div id="Roomlisttext"><Roomtext>'.$Roomthema[$c].'&nbsp;'.listusers_horizontal($Roomname[$c]).'</Roomtext><br></div></td>
    </tr>
  </tbody>
</table>
<table style="border-collapse: collapse; width: 100%;" border="1">
  <tbody>
    <tr>
      <td style="width: 100%;"><a class="floatr" href="core.php?changeroom='.$Roomname[$c].'">Betreten</a></td>
    </tr>
  </tbody>
</table>

';

$c--; 
}

如您所见,我想在正确的位置显示 listusers_horizo​​ntal() 的输出,在我的表内,为我的 Chatroomlist 中的每个打开的房间

这是 listusers_horizo​​ntal() 函数的代码:

<?php

function listusers_horizontal($where){
include("db.php");
$active = $_SESSION["activeroom"];

  $getActlist = "SELECT * FROM `chatlogin` WHERE Room='$where';";

  $getList = mysqli_query($db, $getActlist);

if($getList){
    while($row = mysqli_fetch_object($getList))
    {
      echo $row->User;echo "&nbsp;";
      
    }
}
else{
    echo "Datenbankproblem!";
}

      
}


?>

当我打开页面时,php 将 While() 执行到当前行的末尾并忽略该函数调用,直到该 while() 行的末尾并将其显示在它之后.. 作为它下面的独立 HTML 块

我该怎么做才能让这个 sql 查询输出在确切的位置,它应该在哪里?

标签: phphtmlmysql

解决方案


推荐阅读