Results 1 to 2 of 2

Thread: Print out the MySQL data into textboxes

  1. #1
    Join Date
    Sep 2010

    Print out the MySQL data into textboxes

    I have table (test) in database (dbase) that has 5 columns: idt(primary), datetime, col1, col2 and col3.

    I would like to print out the data into textboxes <input type="text" />.

    This is what I have so far:

    PHP Code:
    mysql_connect(connection string works);
            if (!
    'Could not connect: ' mysql_error());
    $sql "SELECT * FROM test;";
    $result mysql_query($sql$conn);
                    while ((
    $data  mysql_fetch_array($resultMYSQL_ASSOC)) !== null) { 
    '<tr><td>''<input name="Text' $n '" type="text" value= "' $data['idt'] & '" width="25" />''</td>';
    '<td>''<input name="Text' $n '" type="text" value= "' $data['datetime'] & '" width="25" />''</td>';
    '<td>''<input name="Text' $n '" type="text" value= "' $data['col1'] & '" width="25" />''</td>';
    '<td>''<input name="Text' $n '" type="text" value= "' $data['col2'] & '" width="25" />''</td>';
    '<td>''<input name="Text' $n '" type="text" value= "' $data['col3'] & '" width="25" />''</td></tr>';


  2. #2
    Uhm... why are you doing binary 'and' instead of string addition or comma delimits? Replace all those & with commas.

    NOT that being 2014 and not 1997 you have any business with a CENTER tag in your markup, nor being 2014 instead of 2004 should you be using mysql_ functions as we've been told since PHP 5 dropped and as the giant red warning boxes in the manual have been telling us for a couple years. It's also probably not a great idea to be using multiple echo statements to do the job of one, or to have TH that are obviously column headers lacking scope attributes or a THEAD around them. Much less all those bizzare opening and closing of strings for nothing...

    Of course, I'd probably also have the names the same as they are in the database, but with the number index first... and updating your number index per TD is also probably part of your problem, which is why I'd update them per row, not per TD... that or I'd use a parent field -- like that row ID (at least that's what I assume idt is... is that a unique row ID in the table?)

    Something like:
    try {
    	$db = new PDO(
    } catch (PDOException $e) {
    	die('Connection failed: ' . $e->getMessage());
    $statement = $db->query('
    	SELECT idt, datetime, col1, col2, col3 FROM test
    echo '
    	<table id="testData">
    				<th scope="col">idt</th>
    				<th scope="col">datetime</th>
    				<th scope="col">col1</th>
    				<th scope="col">col2</th>
    				<th scope="col">col3</th>
    function makeRow($row, $index) {
    	echo '
    while ($row = $statement->fetch()) {
    	echo '<tr>';
    	foreach ($row as $key => $data) echo '
    						name="test[', $row['idt'], '][', $index, ']" 
    						value="', $row[$index], '"
    	echo '
    echo '
    Though you'd have to re-factor your submit handler accordingly, it would make handling that result output far, far simpler.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center