dongzhuo2010 2015-03-11 05:45
浏览 61
已采纳

使用表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;***

展开全部

  • 写回答

1条回答 默认 最新

  • duan1396 2015-03-11 06: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']."
    ";
          (...)
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部