I have an input form connected to a database. After [the form is submitted], I want to make a form to show all the data which has been input to the database. I want to show this data in table sortable by name or date.
Please help me.
The high-level steps you want to take are:
The following example is a slightly modified version of example #2 from this page on php.net . I suggest you spend a lot of time on that site - the manual is excellent, and almost every page has numerous working examples in the comments section.
<table>
<?php
// Establish the database connection
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");
// Issue the query
$result = mysql_query("SELECT id, name FROM mytable");
// Capture the result in an array, and loop through the array
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
// Print each row as HTML: <tr><td>row 0</td><td>row 1</td>
printf("<tr><td>%s</td><td>%s</td></tr>", $row[0], $row[1]);
}
// Free the result set
mysql_free_result($result);
?>
</table>
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.