这里的PHP新手,
我在MySQL Workbench中有一个包含表格的库数据库:Student,Book和Checkin。我正在尝试使用HTML和PHP在网页上显示它,到目前为止它一直很好,直到尝试在签入表中显示s_id为" s_name"这是学生姓名,b_id到b_name也是一样。我已经在Workbench中创建了外键连接,但无法弄清楚如何创建一个下拉选项,该选项显示我已经在各自的表(而不是s_id和b_id)中创建的学生姓名和书名。
在MS Access中查找字段非常容易,但创建PHP版本已经证明作为初学者很难......现在就是它的样子。
<?php
include('conn.php');
$query=mysqli_query($conn,"select * from `checkin`");
while($row=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $row['c_id']; ?></td>
<td><?php echo $row['s_id']; ?></td>
<td><?php echo $row['b_id']; ?></td>
<td><?php echo $row['c_date']; ?></td>
<td><?php echo $row['c_in']; ?></td>
<td>
<a href="edit_checkin.php?id=<?php echo $row['c_id']; ?>">Edit</a>
<a href="delete_checkin.php?id=<?php echo $row['c_id']; ?>">Delete</a>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
非常感谢任何帮助或提示!
答案 0 :(得分:0)
现在是,现在准备好了查询:
<form action='add_borrowing1.php' method='post'>
<br>
<select name="student">
<?php
$link = mysqli_connect("localhost", "root", "", "library");
$sql = "SELECT DISTINCT studentId, studentName
FROM students";
$result = mysqli_query($link, $sql);
print "<option value='students' selected>Students</option>";
While ($row = mysqli_fetch_assoc($result))
{
print "<option value=" . $row["studentId"] . ">"
. $row["studentName"] . "</option>";
}
?>
</select>
<p>Book:</p>
<br>
<select name="book">
<?php
$link = mysqli_connect("localhost", "root", "", "library");
$sql = "SELECT DISTINCT bookId, bookName
FROM books";
$result = mysqli_query($link, $sql);
print "<option value='books' selected>Books</option>";
While ($row = mysqli_fetch_assoc($result))
{
print "<option value=" . $row["bookId"] . ">"
. $row["bookName"] . "</option>";
}
?>
</select>
<input type="submit" />
</form>
<?php
if (!isset($_GET["raw"])) {
echo "";
}
else {
echo "Borrowing has been successfully added!";
}
?>
add_borrowing.php
======================
<?php
$book = $_POST["book"];
$student = $_POST["student"];
$link = mysqli_connect("localhost", "root", "", "library");
$sql = "INSERT INTO borrowing (bookId, studentId) VALUES (?,?)";
$stmt = mysqli_prepare($link, $sql);
/*
Explanation:
i Integers
d Doubles
b Blobs
s Everything Else
*/
mysqli_stmt_bind_param($stmt, "ii", $book,
$student);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
mysqli_close($link);
header("Location:lib4.php?raw=1");
?>