简体   繁体   中英

PHP- Display data in textarea

My goal is to display all emails inside a text area.

<?php 
$q = "SELECT * FROM `Clients`";
$userData = mysql_query($q);

while($user = mysql_fetch_assoc($userData)){
    echo $user['Email'];
}
?>

it should echo all info into here:

<input type="text" name="text" >

I get the information fine from the DB, but im not sure how to echo the ALL the data into a SINGLE text field..

PHP Code

$userData = mysql_query($q);
$userEmails = array();
while($user = mysql_fetch_assoc($userData)){
    $userEmails[] = $user['Email'];
}

HTML (example with a comma separated email string)

<input type="text" value="<?php echo implode(', ', $userEmails); ?>" />

You need to do in following manner:-

<?php 
$q = "SELECT * FROM `Clients`";
$userData = mysql_query($q);
$email = array(); // create an array
  while($user = mysql_fetch_assoc($userData)){
       $email[] =  $user['Email']; // assign each email to that array
  }
?>

<textarea><?php echo implode(','$email);?></textarea> // implode the array by `,` now all emails will show wiith `,` seperation.

Note:- this is the way how you need to do. Checking variables and do the necessary changes is on you. thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM