olly79 Posted February 8, 2009 Share Posted February 8, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.