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

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记