简体   繁体   English

如何通过外键将带按钮的数据放入表中?

[英]How do I put data with button into a table through foreign key?

I'm working on a web application for school and the goal is to create a several classes and put students in it, and I was thinking, that first think would be insert class and the next thing would be select those classes and put button next it, which would lead to into selecting or inserting students into that specific class. 我正在为学校开发一个Web应用程序,目标是创建几个类并将学生放入其中,我在想,首先想的是插入类,接下来的事情就是选择那些类并按下按钮它会导致选择或插入学生进入特定班级。 And I have problem, because I don't know, how connect the buttons with the those classes, I guess it has something to do with id and attach it to that button, but I have no idea, how should I do that. 我有问题,因为我不知道,如何将按钮与那些类连接起来,我猜它与id有关,并将它附加到那个按钮,但我不知道,我该怎么做。

Two tables, students and classes. 两张桌子,学生和班级。 students has a constraint to the class id. 学生对班级ID有约束。

$sql = "SELECT id, class_name, year FROM class";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {

while($row = mysqli_fetch_assoc($result)) {
    echo "id: " . $row["id"]. " - class name: " . $row["class_name"]. " - Year: " . $row["year"]." <button><a href=index.php?content=students>Enter class</a></button>"."<br>";
   }
}

you can add more variables to the href of the button. 您可以向按钮的href添加更多变量。 Something like classid=$row["id"]. 像classid = $ row [“id”]之类的东西。 Combine variables with the &sign. 将变量与&符号组合在一起。 Then in index.php you can evaluate the value of classid. 然后在index.php中,您可以评估classid的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM