[英]Submitting Changes Made in Table
I have a table in which each row has a name and a dropdown with the names of all possible jobs in my database. 我有一个表,其中每行都有一个名称和一个下拉列表,其中包含数据库中所有可能的作业的名称。 I want the user to be able to assign jobs to however many names that they would like.
我希望用户能够将作业分配给他们想要的许多名称。 Then there will be a submit button that will update the database with only those that have a job selected.
然后将有一个提交按钮,该按钮将仅使用选择了作业的数据库来更新数据库。 I'm not sure how to update only the changed rows, do I make it a form?
我不确定如何仅更新已更改的行,是否将其制成表格? Thanks for your help!
谢谢你的帮助!
HTML: HTML:
<?php
session_start();
if(!isset($_SESSION['login'])) {
header('Location: AdminLogin.php');
exit;
}
$user = 'root';
$password = 'root';
$db = 'Senior Internships';
$host = 'localhost';
$conn = new mysqli($host, $user, $password, $db);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Internships</title>
<link href="css/Navbar.css" rel="stylesheet">
<link href="css/dropdown.css" rel="stylesheet">
<link href="css/Tables.css" rel="stylesheet">
</head>
<body>
<img src="BT-Square-Logo.png" class="logo" alt='BT Logo'>
<script src="js/dropdown.js"></script>
<header>
<div class="container">
<nav>
<ul>
<li><a href='Pre-approved_Internships.php'>Pre-approved Internships</a></li>
<li><a href='Logout.php'>Logout</a></li>
</ul>
</nav>
</div>
</header>
<h2>Students Not Yet Assigned</h2>
<div id="table-wrapper2">
<div id="table-scroll">
<div id="table-wrapper">
<table style="width:100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>1st Area of Interest</th>
<th>2nd Area of Interest</th>
<th>3rd Area of Interest</th>
<th>Internship</th>
</tr>
<?php
$result = mysqli_query($conn, "SELECT FName, LName, AreaofInterest1, AreaofInterest2, AreaofInterest3 FROM Seniors WHERE Visibility=0");
while($row = mysqli_fetch_array($result)):
?>
<tr>
<td><?= $row['FName']; ?></td>
<td><?= $row['LName']; ?></td>
<td><?= $row['AreaofInterest1']; ?></td>
<td><?= $row['AreaofInterest2']; ?></td>
<td><?= $row['AreaofInterest3']; ?></td>
<td>
<select>
<?php
$result2 = mysqli_query($conn, "SELECT Company FROM Internships");
while($row2 = mysqli_fetch_array($result2)): ?>
<option vaue="<?= $row2['Company']; ?>"><?= $row2['Company']; ?></option>
<?php endwhile ?>
</select>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
</div>
</div>
</body>
<footer><p>© Eliav Hamburger 2018 Admins login <a href='AdminLogin.php'>here</a></p></footer>
</html>
CSS Table Formatting (Only Table's CSS Included): CSS表格式(仅包含表的CSS):
td, th {
padding: 10px;
}
table {
border-collapse: collapse;
border: none;
}
th {
color: white;
background-color: #302e7f;
}
th a {
color: white;
text-decoration: none;
}
tr:nth-child(2n+1) {
background-color: #91A6BB;
}
#table-wrapper {
position:relative;
border-style: solid;
border-radius: 7px;
border-color: #91A6BB;
}
#table-scroll {
height:250px;
overflow:auto;
}
#table-wrapper2 table {
width:100%;
}
#table-wrapper2 table thead th .text {
position:absolute;
top:-20px;
z-index:2;
height:20px;
width:35%;
border:1px solid red;
}
first you will add form into the table body. 首先,您将表格添加到表格主体中。
secondly you will add another elements which include sql_rows_id for each users to apply changes for specific users as you want. 其次,您将为每个用户添加另一个包含sql_rows_id的元素,以便根据需要将更改应用于特定用户。
thirdy will add mysqli_query() for applying changes in the database. Thirdy将添加mysqli_query()以在数据库中应用更改。
this is your page code after editing. 这是编辑后的页面代码。
<?php
session_start();
if(!isset($_SESSION['login'])) {
header('Location: AdminLogin.php');
exit;
}
$user = 'root';
$password = 'root';
$db = 'Senior Internships';
$host = 'localhost';
$conn = new mysqli($host, $user, $password, $db);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Internships</title>
<link href="css/Navbar.css" rel="stylesheet">
<link href="css/dropdown.css" rel="stylesheet">
<link href="css/Tables.css" rel="stylesheet">
</head>
<body>
<img src="BT-Square-Logo.png" class="logo" alt='BT Logo'>
<script src="js/dropdown.js"></script>
<header>
<div class="container">
<nav>
<ul>
<li><a href='Pre-approved_Internships.php'>Pre-approved Internships</a></li>
<li><a href='Logout.php'>Logout</a></li>
</ul>
</nav>
</div>
</header>
<h2>Students Not Yet Assigned</h2>
<div id="table-wrapper2">
<div id="table-scroll">
<div id="table-wrapper">
<table style="width:100%">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>1st Area of Interest</th>
<th>2nd Area of Interest</th>
<th>3rd Area of Interest</th>
<th>Internship</th>
</tr>
<?php
$result = mysqli_query($conn, "SELECT FName, LName, AreaofInterest1, AreaofInterest2, AreaofInterest3 FROM Seniors WHERE Visibility=0");
while($row = mysqli_fetch_array($result)):
?>
<form action="" method="post">
<tr>
<td><?= $row['FName']; ?></td>
<td><?= $row['LName']; ?></td>
<td><?= $row['AreaofInterest1']; ?></td>
<td><?= $row['AreaofInterest2']; ?></td>
<td><?= $row['AreaofInterest3']; ?></td>
<td>
<select name="new_data">
<?php
$result2 = mysqli_query($conn, "SELECT Company FROM Internships");
while($row2 = mysqli_fetch_array($result2)): ?>
<option vaue="<?= $row2['Company']; ?>"><?= $row2['Company']; ?></option>
<?php endwhile ?>
</select>
<input type="submit" name="change" />
</td>
</tr>
</form>
<?php endwhile; ?>
</table>
<?php
$id = $row['id'];
$new_data = $_POST['new_data'];
$apply_change = $conn->query("UPDATE Seniors SET /* choose the field to be changed */ field = '$new_data' /* $new_data from select */ WHERE id = $id");
?>
</div>
</div>
</div>
</body>
<footer><p>© Eliav Hamburger 2018 Admins login <a href='AdminLogin.php'>here</a></p></footer>
</html>
i wish you understand me and your problem is solved. 我希望你理解我,你的问题得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.