【问题标题】:Display two columns data in textarea using table PHP使用表格 PHP 在 textarea 中显示两列数据
【发布时间】:2015-03-11 13:45:56
【问题描述】:

我正在尝试在 php 中的 textarea 内的数据库表中的两列中显示数据,在标题标签号和 scc 下

它应该是这样的。

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

这是我的代码,我希望能得到一些关于如何以表格格式或其他简洁方式组织它的建议。 bold 中的行是我在 textarea 中显示了两列数据。 $MyText1 & $Out1 在 textarea 中显示数据。

 // 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;***

【问题讨论】:

  • 不要用锤子灌浆瓷砖。为什么要使用文本区域来存储表格数据?

标签: php mysql textarea


【解决方案1】:

在 textarea 标签内,您可以使用制表符来模拟列,使用 \n 来生成新行。 Textarea 不接受其中的表格标签。您可以从数据库中获取数据,然后使用 \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";
      (...)
}

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 2016-06-06
    • 1970-01-01
    相关资源
    最近更新 更多