我有一个ajax表,它从两个mysql表中读取数据,这些表是
project_ownerships - id_own,项目,代码,own_current,own_future
项目- id,项目,位置,类型,type2,区域,运输,舞台
使用联接表sql查询,数据可以很好地读入网页表。
$query_value = isset($_GET['value']) ? $_GET['value'] : "";
$sql = "SELECT project_ownerships.*, projects.*
FROM project_ownerships, projects
WHERE project_ownerships.project = projects.project
AND project_ownerships.code = $query_value'";
$result = $mysqli->query($sql);但是,我无法使编辑更新正常工作。我只能从一个db表中获得一个data - id值。
因此,属于projects表的任何更新都可以更新,但是对project_ownerships的任何更新都不具有正确的id值并更新错误的db-记录。
这是更新函数。此函数返回错误“未找到索引或名称id_own的列”。
$.ajax({
url: 'update_multi.php',
type: 'POST',
dataType: "html",
data: {
tablename: editableGrid.getColumnName(columnIndex) == "own_current" ? "project_ownerships" : "projects",
id: editableGrid.getColumnName(columnIndex) == "own_current" ? editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")) : editableGrid.getRowId(rowIndex),
newvalue: editableGrid.getColumnType(columnIndex) == "boolean" ? (newValue ? 1 : 0) : newValue,
colname: editableGrid.getColumnName(columnIndex),
coltype: editableGrid.getColumnType(columnIndex)
},
success: function (...,
error: function(...,
async: true
});下面是php更新
$tablename = $mysqli->real_escape_string(strip_tags($_POST['tablename']));
$id = $mysqli->real_escape_string(strip_tags($_POST['id']));
$value = $mysqli->real_escape_string($_POST['newvalue']);
$colname = $mysqli->real_escape_string(strip_tags($_POST['colname']));
$coltype = $mysqli->real_escape_string(strip_tags($_POST['coltype']));
$id_column = "";
if ($tablename == "projects") {$id_column = "id";} else {$id_column = "id_own";}
if ( $stmt = $mysqli->prepare("UPDATE ".$tablename." SET ".$colname." = ? WHERE ".$id_column." = ?")) {
$stmt->bind_param("si",$value, $id);
$return = $stmt->execute();
$stmt->close();
}基本上我想做的是..。
如果从sql中删除projects.id,则更新将无法工作。
如果将project_ownership.id_own更改为project_ownership.id并删除projects.id,则更新将有效,但仅适用于project_ownership.*字段
所以..。我需要sql查询中的一个名为*.id的列。
另外,在发送更新时,可以由
tablename: editableGrid.getColumnName(columnIndex) == "own_current" ? "project_ownerships" : "projects", 所以使用相同的逻辑
id: editableGrid.getColumnName(columnIndex) == "own_current" ? editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")) : editableGrid.getRowId(rowIndex), 首先,认识到own_current存在,并将参数传递给editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own")),但返回的错误是“没有找到带有id_own名称的列”.?
我真的很困惑..。
它不能不存在(从sql中删除),否则更新就会冻结。
但当它在那里时却找不到..。
任何帮助都是很好的
如何定义ajax - data - id列或rowIndex列?
我的理论是
editableGrid.getRowId(rowIndex)
可能是这样的(很明显,如果不是这样的话,这是可行的)
editableGrid.getValueAt(rowIndex, editableGrid.getColumn("id_own"))
但我也试过
editableGrid.getValueAt(rowIndex, editableGrid.getColumnIndex("id_own"))
返回“无效列索引-1”。
和
editableGrid.getValueAt(rowIndex, editableGrid.getColumnName("id_own"))
更新
editablegrid中有几个私有函数定义了行id。因此,我想这是一个简单的问题,而不是javascript、ajax或php的问题。
发布于 2012-08-09 11:03:17
您应该将SQL查询中每个表的"id“列重命名为”AS“操作符,这样它们就不会发生冲突。
例如:
SELECT B.*,A.name,A.id as author_id FROM BOOKS B
INNER JOIN AUTHORS A ON A.id=B.authoridhttps://stackoverflow.com/questions/11344155
复制相似问题