Solved

Simple editable html table

Posted on 2011-03-08
4
381 Views
Last Modified: 2012-05-11
How can I find a simple, editable html table.

I just need to edit one row at a time and submit the changes to a database.

The simplest possible solution would be appreciated.
0
Comment
Question by:pillmill
  • 2
4 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
For example :
<!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=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.5.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("input", "table").blur(function() {
			if( confirm("apply changes") ) $.post("update.php", { "id":$(this).attr("id"), "val":$(this).val() } );
		});
	});
</script>
</head>
<body>
<table>
<tr><td><input id="1" value="10" /></td></tr>
<tr><td><input id="2" value="25" /></td></tr>
</table>
</body>
</html>

Open in new window


Server side something like :
<?PHP
	include "includes/connect.inc";

	if( isset($_REQUEST["id"]) && isset($_REQUEST["val"]) ) {

		$id = mysql_real_escape_string($_REQUEST["id"]);
		$val = mysql_real_escape_string($_REQUEST["val"]);
		
		$query = "UPDATE myTable SET myField=$val WHERE id=$id";
		$result = mysql_query($query,$connexion);

		if(!$result) {
			echo mysql_errno($connexion) . "\n";
			die("bad query : " . mysql_error());
		}
	}
?>

Open in new window

0
 
LVL 2

Expert Comment

by:cyberhitesh
Comment Utility
Check out dhtmlxGrid is an Ajax-enabled JavaScript grid control it allows you to show data in table and also provides you functionality to edit and save the data using Ajax call.

URL: http://dhtmlx.com/docs/products/dhtmlxGrid/
0
 

Author Comment

by:pillmill
Comment Utility
Thanks leakim971:

Is it possible to make this editable by row?

0
 
LVL 82

Expert Comment

by:leakim971
Comment Utility
this is the case.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now