dongzhuo2010
2015-03-11 13:45
浏览 56
已采纳

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

I am trying to display the data from two columns in a database table inside a textarea in php, under the headings tag number and scc

It should read something like this.

enter image description here

However it reads all in one line with no breaks and it looks messy:

enter image description here

Here is my code, I would appreciate some advice on how to structure this in a table format or something neat. The lines in bold are were I have displayed the two columns data in the textarea. $MyText1 & $Out1 displays the data in the 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;***

图片转代码服务由CSDN问答提供 功能建议

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

它应该是这样的。

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

< img src =“https://i.stack.imgur.com/XNiyB.png”alt =“在此处输入图像说明”>

这是我的代码,我将不胜感激 关于如何以表格格式或整洁的方式构造它。 粗体 中的行是我在textarea中显示的两列数据。 $ MyText1&amp; $ 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 ='&lt; p  align =“left”&gt;&lt; textarea rows =“5”cols =“25”disabled =“true”&gt;'  。$ MSG1。  '&lt; / textarea&gt;&lt; / p&gt;'; 
 // mysqli_fetch_array($ result)
 // echo $ out1; 
 
 
 
 if($ row ['scc']&gt; 50  ){
 $ msg =(“'Somanic细胞计数水平满足牛群中的预期输出水平。'$ MyText。'高于平均水平''根据当前生产水平不应采取进一步行动'”);  
 // $ msg = $ TagNumber; 
 
 // echo $ row。$ TagNumber; 
} 
 elseif($ Scc&lt; $ average){
 $ msg ='SCC级别低于平均值 。'; 
}其他{
 $ msg ='其他一些消息'; 
} 
} 
 *** $ out1 ='&lt; p align =“left”&gt;&lt; textarea rows =“  5“cols =”25“disabled =”true“&gt;'。$ msg1。$ MyText1。  '&lt; / textarea&gt;&lt; / p&gt;'; *** 
 // mysqli_fetch_array($ result)
 *** echo $ out1; *** 
   
 <  / DIV>
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duan1396 2015-03-11 14:17
    已采纳

    Inside the textarea tag you can use the tab character to simulate the columns and the to generate new lines. Textarea does not accept a table tag inside it. You can get the data from your database and then separate it using the and \t tags. Your code should be something like this:

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

    The blank spaces closer to the \t and are no mandatory. But rember: the and \t characeters should always be echoed with " and not with '.

    UPDATE

    Base on your code, you can try something like this:

    $myText = "TagNumber: \t\t Scc:
    ";
    while ($row = mysql_fetch_array($result)){
          $myText .= $row['tag_number']."\t\t".$row['scc']."
    ";
          (...)
    }
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题