Solved

Simple editable html table

Posted on 2011-03-08
4
404 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
ID: 35076007
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
ID: 35085452
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
ID: 35089898
Thanks leakim971:

Is it possible to make this editable by row?

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35089944
this is the case.
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
age from date of birth 4 42
Can't get container centered 4 16
Select case on click 3 16
mysqli_connect error on wamp but not on remote server 8 27
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

778 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