Javascript jQuery基于mysql表更新html表
我有一个MySQL数据库,里面有两个表 我使用的主要文件是index.php、jquery.js、jfunc.js和urlmappingDB.php 我的主要问题与前三个问题有关。在index.php中,我用html标记显示urlmappingDB.php中的数据表中的数据。当我单击表下的update按钮时,我希望在html表的相应位置显示更新后的MySQL表数据。我觉得我当前的jquery代码不足以更新一个表,因为它传递到\u POST数组中的变量在我的程序中几乎是任意变量 也就是说,我的雇主更希望我使用jquery来实现这一点,所以我有点困惑于如何实现这一点。我该怎么办 index.phpJavascript jQuery基于mysql表更新html表,javascript,php,jquery,html-table,Javascript,Php,Jquery,Html Table,我有一个MySQL数据库,里面有两个表 我使用的主要文件是index.php、jquery.js、jfunc.js和urlmappingDB.php 我的主要问题与前三个问题有关。在index.php中,我用html标记显示urlmappingDB.php中的数据表中的数据。当我单击表下的update按钮时,我希望在html表的相应位置显示更新后的MySQL表数据。我觉得我当前的jquery代码不足以更新一个表,因为它传递到\u POST数组中的变量在我的程序中几乎是任意变量 也就是说,我的雇主
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die("Error: ".mysql_error());
}
mysql_select_db("genius", $con);
$result = mysql_query("SELECT * FROM `urlMappingConsumption`");
?>
<!DOCTYPE html>
<html>
<head>
<script type ="text/javascript" src ="jquery.js"></script>
<script type ="text/javascript">
function get() {
$.post('urlmappingDB.php', {},
function(output) {
$('#urlmappingdata').html(output).show();
});
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<table id="urlConsumptionTable">
<thead>
<tr>
<th>urlConsumptionID</th>
<th>customerID</th>
<th>activityID</th>
<th>numOccurences</th>
<th>lastModified</th>
</tr>
</thead>
<tbody>
<?php while($row = mysql_fetch_array($result)) {?>
<tr>
<td><?=$row['urlMappingConsumptionID']?></td>
<td><?=$row['customerID']?></td>
<td><?=$row['activityID']?></td>
<td><?=$row['numOccurences']?></td>
<td><?=$row['lastModified']?></td>
</tr>
<?php } ?>
</tbody>
</table>
<div id="urlmappingdata"></div>
<form name="form">
<input type="button" value="Update" id="update">
</form>
<script type="text/javascript" src="jfunc.js"></script>
</body>
</html>
及
urlMapping.csv
INSERT INTO urlMapping (urlMappingID,customerID,activityID,contactID,fullURL,lastModified,developerSandbox)
VALUES
(7549046856,57544,2191972,166419052,'http://www.salesgenius.com/activities/emailOpened.php','2 012-06-1422:53:51','/webapp/webroot/'),
(7549046855,57544,2191972,166419052,'https://www.salesgenius.com/activities/unsubscribe.php','2012-06-1422:53:51','/webapp/webroot/'),
(7549046854,57544,2191972,166419052,'http://security.intuit.com/privacy/marketing-preferences.html','2012-06-1422:53:51','/webapp/webroot/'),
(7549046853,57544,2191972,166419052,'https://privacy.intuit.com/cpi/do/signin','2012-06-1422:53:51','/webapp/webroot/'),
(7549046852,57544,2191972,166419052,'http://ps.genius.com/intuit/pos/index_c.html','2012-06-1422:53:51','/webapp/webroot/'),
etc...
可以使用ajax,但是onclick不是在php文件中获取原始数据,而是将数据放在一个表中,然后将其发送到主页
$.ajax({
url: "table.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
alert("HTLM = " + html);
$('#table').html(html);
}
});
table是您的表要放置的div
html是ajax从php文件=表中获取的内容
它将html放在表div中
如果您仍然需要帮助,请评论您的代码是-我现在将其编辑为一个绝对、可怕的混乱。我希望没有人需要维护你写的东西,我真的需要。
DROP TABLE IF EXISTS `urlMapping`;
SET @saved_cs_client = @@character_set_client;
SET character_set_client = utf8;
CREATE TABLE `urlMapping` (
`urlMappingID` bigint(20) unsigned NOT NULL auto_increment,
`customerID` int(11) default '0',
`activityID` int(11) default '0',
`contactID` int(11) default '0',
`fullURL` mediumtext,
`lastModified` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
`developerSandbox` varchar(25) default '',
PRIMARY KEY (`urlMappingID`),
KEY `customerActivityID` (`customerID`,`activityID`)
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
SET character_set_client = @saved_cs_client;
INSERT INTO urlMapping (urlMappingID,customerID,activityID,contactID,fullURL,lastModified,developerSandbox)
VALUES
(7549046856,57544,2191972,166419052,'http://www.salesgenius.com/activities/emailOpened.php','2 012-06-1422:53:51','/webapp/webroot/'),
(7549046855,57544,2191972,166419052,'https://www.salesgenius.com/activities/unsubscribe.php','2012-06-1422:53:51','/webapp/webroot/'),
(7549046854,57544,2191972,166419052,'http://security.intuit.com/privacy/marketing-preferences.html','2012-06-1422:53:51','/webapp/webroot/'),
(7549046853,57544,2191972,166419052,'https://privacy.intuit.com/cpi/do/signin','2012-06-1422:53:51','/webapp/webroot/'),
(7549046852,57544,2191972,166419052,'http://ps.genius.com/intuit/pos/index_c.html','2012-06-1422:53:51','/webapp/webroot/'),
etc...
$.ajax({
url: "table.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
alert("HTLM = " + html);
$('#table').html(html);
}
});