1

我有两个这样的表:

[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>";   

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

在表格下方的主页中,我通常会这样做:

伪代码

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>"; 

自从表连接后,这是如何工作的?我如何编辑它们?

4

1 回答 1

3

我认为您应该单独更新每个表;首先是主表,然后是详细表,然后重新绑定您的数据视图

于 2012-05-07T15:17:03.033 回答