简体   繁体   中英

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. 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.

Two tables, students and classes. students has a constraint to the class 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. Something like classid=$row["id"]. Combine variables with the &sign. Then in index.php you can evaluate the value of classid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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