Reputation: 19
Hi actually when i execute the code i get an output it will be spitted in echo statement but if i put echo in textarea i get only last value of string from my database
$sql = mysqli_query($con, "SELECT naveen from kumar where id<5");
while ($row = mysqli_fetch_array($sql)) {
$myString = $row['admin'];
$myArray = explode(',', $myString);
foreach ($myArray as $my_Array) {
echo $my_Array.'<br>';
}
}
?>
<form method="post" action="">
<textarea name="valid" cols="60" rows="5"><?php echo $my_Array;?></textarea>
</form>
<?php ?>
This is my result
Upvotes: 0
Views: 169
Reputation: 101
You should paint a <textarea>
inside of first bucle (while
).
echo '<form method="post" action="">';
$sql = mysqli_query($con, "SELECT naveen from kumar where id<5");
while ($row = mysqli_fetch_array($sql)) {
$myString = $row['admin'];
$myArray = explode(',', $myString);
echo '<textarea name="valid" cols="60" rows="5">';
foreach ($myArray as $my_Array) {
echo = $my_Array.'<br>';
}
echo '</textarea>';
}
?>
</form>
Upvotes: 1
Reputation: 1202
You have to do it like this:
<form method="post" action="">
<?php $sql = mysqli_query($con, "SELECT naveen from kumar where id<5");
while ($row = mysqli_fetch_array($sql)) {
$myString = $row['admin'];
$myArray[] = explode(',', $myString);
}
?>
<textarea name="valid" cols="60" rows="5"><?php echo implode(" ",$my_Array);?></textarea>
</form>
<?php ?>
Upvotes: 0
Reputation: 16436
You need to concatenate your result with previous one. Delcare $my_Array = "";
before while
loop For break line in textarea you have to use
foreach ($myArray as $my_Array) {
$my_Array .= ' ';
echo $my_Array; //IF you also want to echo here
}
Upvotes: 1
Reputation: 3
I hope this example will solve your issue. Please let me know if you still have any queries.
<?php
$myvalue = array('one','two','three');
$myterm = implode('-', $myvalue);
$mynewvalue = explode('-',$myterm);
?>
<form method="post" action="">
<textarea name="valid" cols="60" rows="5">
<?php
foreach($mynewvalue as $mvn)
{
echo $mvn.',';
}
?>
</textarea>
</form>
Upvotes: 0