我正在尝试在 php 中的文本区域内的数据库表中的标题标记号和 scc 下显示两列的数据
它应该是这样的。
但是它在一行中读取所有内容,没有中断,看起来很困惑:
这是我的代码,我希望得到一些关于如何以表格格式或简洁的方式构建它的建议。 粗体中的行是我在文本区域中显示两列数据的情况。 $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;***
最佳答案
在文本区域标记内,您可以使用制表符来模拟列,并使用\n 来生成新行。文本区域不接受其中包含表格标签。您可以从数据库中获取数据,然后使用\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";
(...)
}
关于php - 使用PHP表在textarea中显示两列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28988292/