Jump to content

MySQL Data into TextArea


olly79

Recommended Posts

Hi,

 

Just wondering if someone could take a look at my code and assist:

 

<?php
$database="mydbname";
mysql_connect ("localhost", "myusername", "mypassword");
@mysql_select_db($database) or die( "Unable to select database");
$result = mysql_query( "SELECT * FROM recruitment" )
or die("SELECT Error: ".mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php
  $table = (isset($_POST['table']) && $_POST['table'] != "") ? $_POST['table'] : "";
?>
<form action="insert.php" method="post">
  <input type="text" name="table" value="<?php echo $table; ?>" />
  <textarea>
<?php
  if($_SERVER['REQUEST_METHOD'] == "POST" && $table != ""){
      $sql = mysql_query(" SELECT * FROM table");
  $f = 0; //for showing the fields.
  while($arr = mysql_fetch_array($sql)){
    if($f == 0){
      $f++; //this is so we never show the fields again
      //dump fields
      $rl = 0; //just to make a separator
      $j = 1; //field count
      foreach($arr as $key => $value){
        $j++;
        if($j % 2){ //mysql will give us numeric and text values as keys, we want to skip numeric
          $rl += strlen($key);
          echo strtoupper($key) . "\t";
        }
      }
      echo "\n" . str_repeat("-", $rl) . "\n"; //this is the separator
    }
    $i = 1;
    foreach($arr as $key => $value){
      $i++;
      if($i % 2){ //again, skipping numeric field values
        echo $value . "\t";
      }
    }
    echo "\n";
  }
?>
  </textarea>
  <input type="submit" value="Load Data" />
</form>
</body>
</html>

 

Previously my webform had the following layout:

 

<textarea name="recruitment" rows="20" cols="150" wrap="physical"><?php
  $sql = mysql_query(" SELECT * FROM table");
  $f = 0; //for showing the fields.
  while($arr = mysql_fetch_array($sql)){
    if($f == 0){
      $f++; //this is so we never show the fields again
      //dump fields
      $rl = 0; //just to make a separator
      $j = 1; //field count
      foreach($arr as $key => $value){
        $j++;
        if($j % 2){ //mysql will give us numeric and text values as keys, we want to skip numeric
          $rl += strlen($key);
          echo strtoupper($key) . "\t";
        }
      }
      echo "\n" . str_repeat("-", $rl) . "\n"; //this is the separator
    }
    $i = 1;
    foreach($arr as $key => $value){
      $i++;
      if($i % 2){ //again, skipping numeric field values
        echo $value . "\t";
      }
    }
    echo "\n";
  }
?></textarea>
<br />
<INPUT TYPE="submit" value="load data">
<INPUT TYPE="submit" value="export data" />

 

However, I now want the "load data" button to load the MySQL data and wanted it to do into the TextArea I had defined. Can anyone please assist.

Link to comment
https://forums.phpfreaks.com/topic/144375-mysql-data-into-textarea/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.