我创建了一个聊天系统,学生和学术人员可以在它们之间进行交流。我已经开发出一种表格,可以在对话存在的情况下获取俱乐部的名称,以及出于其他原因使用staff_id
的值。
问题是我无法从3个表中删除记录。我知道我首先必须检查staff_table
或stu_table
中是否存在特定的ID,但是我无法弄清楚必须使用的查询。
第一个表是staff_message
(列:staff_id, m_id
),第二个表是stu_message
(列:stu_id, mid
),第三个表是{{1} }表(列:message
)。
在这里您可以看到我的代码:
id, text, date, type
提前谢谢!
编辑:我分别测试了每个代码,发现它们都可以工作。我的意思是,当只有一条学生留言时,该留言以及参考表( <?php
include_once('connect.php');
$name=mysqli_real_escape_string($con,$_POST['clubname']);
$staff_id=mysqli_real_escape_string($con,$_POST['staff_id']);
if(empty($name)) {
header("Location: ../options.php?index==empty");
exit();
}
else {
$quer = mysqli_query($con,"SELECT id FROM message WHERE type='$name'");
while($row = mysqli_fetch_array($quer)) {
$message_id = $row['id'];
}
$query4 = mysqli_query($con,"SELECT * FROM staff_message WHERE m_id='$message_id'");
if(mysqli_num_rows($query4) >= 1)
{
$query5 = mysqli_query($con,"DELETE FROM staff_message WHERE m_id='$message_id'");
} else {
echo "not here staff"; //see if finds the value
}
$query8 = mysqli_query($con,"SELECT * FROM stu_message WHERE mid='$message_id'");
if(mysqli_num_rows($query8) >= 1)
{
$query5 = mysqli_query($con,"DELETE FROM stu_message WHERE mid='$message_id'");
} else {
echo "not here stu";//see if finds the value
}
$query= mysqli_query($con,"DELETE FROM message WHERE type = '$name'");
header("Location: ../options.php?delete==success");
}
?>
中的那一行都将被删除。这也适用于教职员表。
答案 0 :(得分:0)
可能是 你有3张桌子 1.工作人员消息 2.Stu_Message 3.消息
您能告诉我表中哪些是主要ID,哪些ID为Refreence,然后我可以根据您的要求进行查询
答案 1 :(得分:0)
根据您的图像,基表是消息,然后中间引用两个表(stu_message和staff_message)---对吗?