Insert MYSQL data into HTML Textarea

mysql_into_textarea
Follow the link below, the link will open new page to my demonstration.Insert MYSQL into Textarea

The concept is very easy and the main PHP code is below.

<html>
<head>

<?php
//make an object array
$arrayobj = new ArrayObject();
//connect to database
$con=mysqli_connect("localhost","username","password","db");
//check connection
if(mysqli_connect_errno())
{
echo "Failed to connect to MySQL:".mysqli_connect_error();
}

$result=mysqli_query($con,"SELECT * FROM table");

while($row=mysqli_fetch_array($result))
{
$arrayobj->append($row['firstname']);
}

mysqli_close($con);
?>

</head>
<body>
<textarea id="myTextarea" rows="25" cols="25"><?php foreach($arrayobj as $value){
echo $value . "\n";}?>
</textarea>
<br>

</body>
</html>

As you can see connecting to database is as usual. The key is the $arrayobj = new ArrayObject() which make this string into an array and the $arrayobj->append (appends) to that array.

Leave a Reply

Your email address will not be published. Required fields are marked *