Subject: php question
Posted By: hosefo81 Post Date: 1/28/2004 8:00:55 AM
i have two text box. a add button and a table. after each time a user enter a product id and quantity to the textbox, and then clicked the add button, the entered data and the previously entered data will be displayed on the table.
My question is : is it possible to displayed all the entered data each time after the button is clicked?

Reply By: nikolai Reply Date: 1/28/2004 1:02:32 PM
Yes, it's very easy.  If you're storing all the user input in a database, just select all the input that the user submitted from the database and generate your HTML table from that.

In pseudo-php:

<?php

db_connect(...);


// Insert any new rows into the database.
if (isset($_POST['new_entry']))
{
    db_query("insert new entry into database");
}


// Get all the rows from the database and output them in a table.
$result = db_query("select all rows from database");

echo "<table>\n";

// each database row is output in its own table row.
while ($row = db_fetch_array($result))
{
   echo "  <tr>\n";
   echo "    <td>{$row['col1']}</td>\n";
   echo "    <td>{$row['col2']}</td>\n";
   echo "    ...\n";
   echo "  </tr>\n";
}
echo "</table>\n";


// output the form to create a new row.
echo "<form method=\"post\" action=\"{$_SERVER['PHP_SELF']}\">\n";
echo "  <input ... />\n";
echo "</form>

?>


Take care,

Nik
http://www.bigaction.org/

Go to topic 9073

Return to index page 960
Return to index page 959
Return to index page 958
Return to index page 957
Return to index page 956
Return to index page 955
Return to index page 954
Return to index page 953
Return to index page 952
Return to index page 951