爆炸函数返回textarea中的单行

时间:2017-08-03 06:20:20

标签: javascript php mysql textarea explode

嗨,实际上当我执行代码时我得到一个输出它会在echo语句中吐出但是如果我把echo放在textarea中我只得到我数据库中字符串的最后一个值

    $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 ?>

这是我的结果

enter image description here

4 个答案:

答案 0 :(得分:1)

你应该在第一个bucle(<textarea>)内画一个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>

答案 1 :(得分:1)

您需要将结果与之前的结果连接起来。在$my_Array = "";循环之前的Delcare while对于textarea中的分隔线,您必须使用&#10;

foreach ($myArray as $my_Array) {
$my_Array .= '&#10;';
echo $my_Array; //IF you also want to echo here
}

答案 2 :(得分:0)

我希望这个例子可以解决你的问题。如果您还有任何疑问,请与我们联系。

<?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>

答案 3 :(得分:0)

你必须这样做:

    <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 ?>