[英]Data manipulation PHP - MySQL
I'm new to PHP.我是 PHP 的新手。 I have a list of books with a reserve button next to each.
我有一个书籍清单,每本书旁边都有一个预订按钮。 Once a user clicks reserve it decreases the number of copies by one and removes the list item if there are no more copies.
一旦用户单击保留,它会将副本数量减少一,如果没有更多副本,则删除列表项。
That's how I did it (not sure if it is right?):我就是这样做的(不确定是否正确?):
<?php
$query = "SELECT * from book";
$stmt;
$stmt = $db->prepare($query);
$stmt->bind_result($ISBN, $Title, $NoPages, $NoEdition, $NoCopies, $PubYear, $Publisher, $AuthorID);
$stmt->execute();
echo "<ul>";
while ($stmt->fetch()){
if ($NoCopies > 0){echo "<li> <b> $Title </b><i>published $PubYear with $NoPages pages </i>- Only $NoCopies copies left! <form action='reserve.php' method='POST'><input type='submit' name='sub' value='Reserve'></form> </li>";
echo "<br>";
echo "<li>$AuthorID</li>";
echo "<br>";
}
if ($NoCopies == 1){
echo "<li> <b> $Title </b><i>published $PubYear with $NoPages pages </i>- Only $NoCopies copies left! <form action='reserve.php' method='POST'></form> </li>";
echo "<br>";
echo "<li>$AuthorID</li>";
echo "<br>";
}
}
echo "</ul>";
$stmt->close();
?>
What I have no idea about is: how do I make each button target a specific book??我不知道的是:如何使每个按钮针对特定的书? So that when reserve is clicked only number of Copies for the book next to it is changed.
因此,当单击保留时,仅更改旁边书籍的副本数。
I would appreciate any help!我将不胜感激任何帮助! Thank you!
谢谢!
I'm new to PHP.我是 PHP 的新手。 I have a list of books with a reserve button next to each.
我有一个书籍清单,每本书旁边都有一个预订按钮。 Once a user clicks reserve it decreases the number of copies by one and removes the list item if there are no more copies.
一旦用户单击保留,它会将副本数量减少一,如果没有更多副本,则删除列表项。
That's how I did it (not sure if it is right?):我就是这样做的(不确定是否正确?):
<?php
$query = "SELECT * from book";
$stmt;
$stmt = $db->prepare($query);
$stmt->bind_result($ISBN, $Title, $NoPages, $NoEdition, $NoCopies, $PubYear, $Publisher, $AuthorID);
$stmt->execute();
echo "<ul>";
while ($stmt->fetch()){
if ($NoCopies > 0){echo "<li> <b> $Title </b><i>published $PubYear with $NoPages pages </i>- Only $NoCopies copies left! <form action='reserve.php' method='POST'><input type='submit' name='sub' value='Reserve'></form> </li>";
echo "<br>";
echo "<li>$AuthorID</li>";
echo "<br>";
}
if ($NoCopies == 1){
echo "<li> <b> $Title </b><i>published $PubYear with $NoPages pages </i>- Only $NoCopies copies left! <form action='reserve.php' method='POST'></form> </li>";
echo "<br>";
echo "<li>$AuthorID</li>";
echo "<br>";
}
}
echo "</ul>";
$stmt->close();
?>
What I have no idea about is: how do I make each button target a specific book??我不知道的是:如何使每个按钮针对特定的书? So that when reserve is clicked only number of Copies for the book next to it is changed.
因此,当单击保留时,仅更改旁边书籍的副本数。
I would appreciate any help!我将不胜感激任何帮助! Thank you!
谢谢!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.