使用 table PHP 在 textarea 中显示两列数据

Display two columns data in textarea using table PHP

我正在尝试在 php 的文本区域中显示数据库 table 中两列的数据,在标题标签编号和 scc

它应该是这样的。

然而,它在一行中读取所有内容,没有中断,看起来很乱:

这是我的代码,我将不胜感激关于如何以 table 格式或其他简洁的格式构建它的建议。 bold 中的行是我在文本区域中显示了两列数据。 $MyText1 & $Out1 显示文本区域中的数据。

 // mysqli_fetch_assoc
    $myquery = "SELECT  `scc`, `tag_number` FROM  `milk` 
";

         $result = mysql_query($myquery);

$MyText = "";
$MyText1 = "";

    //$row = mysql_fetch_array($result);
  while ($row = mysql_fetch_array($result)) 
  {

  $Scc = $row['scc'];
    $TagNumber= $row['tag_number']; 
    //$MyText.= $row['tag_number']; 
    $MyText .= $TagNumber . ', ';
    ***$MyText1 .= $TagNumber . $Scc . ',';***

   ***$msg1 = "TagNumber :   Scc : " .$row[0].$row[1];*** 
  // $out1 = '<p align="left"><textarea rows="5" cols="25" disabled = "true">' .$msg1. '</textarea></p>';
    //mysqli_fetch_array($result) 
//  echo $out1;



     if($row['scc'] > 50 ) {
        $msg = ("'Somanic cell count levels are meeting the expected output levels in the herd.' $MyText. 'are above the average' 'No further action should be taken according to current production levels '");
    //$msg = $TagNumber;

//echo $row.$TagNumber;
}
    elseif ($Scc < $average) {
        $msg = 'SCC levels are below the average.';
    }else{
        $msg = 'some other message';
    }
  }
    ***$out1 = '<p align="left"><textarea rows="5" cols="25" disabled = "true">'.$msg1.$MyText1.  '</textarea></p>';***
    //mysqli_fetch_array($result) 
    ***echo $out1;***

在 textarea 标签内,您可以使用制表符模拟列,使用 \n 生成新行。 Textarea 不接受其中的 table 标签。您可以从数据库中获取数据,然后使用 \n 和 \t 标记将其分隔。您的代码应该是这样的:

echo "Column1Title: \t Column2Title \n";
...
echo "Column1Data1 \t Column2Data2 \n";
...

靠近 \t 和 \n 的空格不是强制性的。但请记住:\n 和 \t 字符应始终与 " 相呼应,而不是与 '.

更新

根据您的代码,您可以尝试这样的操作:

$myText = "TagNumber: \t\t Scc:\n";
while ($row = mysql_fetch_array($result)){
      $myText .= $row['tag_number']."\t\t".$row['scc']."\n";
      (...)
}