i want to diplay values from database to table.then i want to edit new value to the same field and post to database.how can i do it using php codes.please help me

Member Avatar


Although this sounds quite simple, it has a few different solutions, none of which are that straightforward.

You will need to:

1) Retrieve the info required from the DB into a recordset object ( mysql_query ).
2) Loop through the object (using while ), tranferring the data to an array variable (e.g. $data ) using mysql_fetch_array .
3) Extract the data for your table and insert this into html format:

echo "<table><thead><tr><th>Name</th><th>Age</th><th>Gender</th><th>ACTION</th></tr></thead><tbody>";
while($data = mysql_fetch_array($result)){
 echo "<tr><td>{$data['user_name']}</td><td>{$data['user_age']}</td><td>{$data['user_sex']}</td><td><a href="editmember.php?id={$data['user_id']}" >EDIT</a></td></tr>";
echo "</tbody></table>";

4) You will get a table with the last column giving you an EDIT link that takes you to the editmember.php page with a form for editing that particular member.

5) You need to retrieve the members details from the DB using the



6) Place the member's old details into the form.

7) You then overwrite the new details and submit the form.

8) The form handler should make the appropriate updates (if possible) and then return you to your table page.

NOTICE that there are many ways to achieve this type of functionality. The above is a quick and easy method. AJAX methods are far slicker. Some js/ajax frameworks like EXT allow the updating of table data directly from the table. Seeing as you're a newbie, I thought I'd stick to the basics.

If you do not understand much of the above, please consult some online tutorials on php or buy a good (recent!) book.

i have done the edit part using your code.thank you for help me