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.
However it reads all in one line with no breaks and it looks messy:
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;***
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']."
";
(...)
}