gpt4 book ai didi

php - MySQL 一次更新两个不同的表(CRUD)

转载 作者:行者123 更新时间:2023-11-29 05:36:04 25 4
gpt4 key购买 nike

我有两个这样的表:

[tblFacilityHrs] id uid title description

[tblFacilityHrsDateTimes] owner_uid startEventDate endEventDate startTime endTime days recurrence finalDate

我加入的表格如下:

$result = mysql_query("SELECT * FROM tblFacilityHrs JOIN tblFacilityHrsDateTimes ON tblFacilityHrs.uid =tblFacilityHrsDateTimes.owner_uid") or trigger_error(mysql_error());

为了显示这两个表,我遍历每条记录并将其全部放在一个表中:

while($row = mysql_fetch_array($result)){ 
foreach($row AS $key => $value) { $row[$key] = stripslashes($value); }
echo "<tr>";
echo "<td valign='top'>" . nl2br( $row['title']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['description']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['startEventDate']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['endEventDate']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['startTime']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['endTime']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['days']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['recurrence']) . "</td>";
echo "<td valign='top'>" . nl2br( $row['finalDate']) . "</td>";

我现在的问题是,如何编辑每条记录?

在 table 下面的主页中,我通常会这样做:

伪代码

echo "<td valign='top'><a href=edit.php?id={$row['id']}>Edit</a></td><td><a href=delete.php?id={$row['id']}>Delete</a></td> "; 

然后在我的编辑页面上我会做这样的事情:

伪代码

if (isset($_GET['id']) ) { 
$id = (int) $_GET['id'];
if (isset($_POST['submitted'])) {
foreach($_POST AS $key => $value) { $_POST[$key] = mysql_real_escape_string($value); }
$sql = "`title` = '{$_POST['title']}' , `description` = '{$_POST['description']}' WHERE `id` = '$id' ";
mysql_query($sql) or die(mysql_error());
echo (mysql_affected_rows()) ? "Edited row.<br />" : "Nothing changed. <br />";
echo "<a href='list.php'>Back</a>";

表连接后,这是如何工作的?我怎样才能编辑它们?

最佳答案

我认为您应该分别更新每个表;首先是主表,然后是明细表,然后重新绑定(bind)您的数据 View

关于php - MySQL 一次更新两个不同的表(CRUD),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10484559/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com