问题在于,何时使用带有change_admin表单中的选项的select,它不会仅对应该更改的产品进行更改,而且对于同一商店中的其他产品也不会更改,我不希望这样。我工作了4个小时,但我找不到解决方案。
这是一个想法(我知道代码不是代码,但它提供了我想要实现的目标以及如何实现):
<form method="post">
<select name="store">
<option value="1">amsterdam</option>
<option value="2">rotterdam</option>
<option value="3">den haag</option>
</select>
<input type="submit" name="store" id="store" value="change city" />
</form>
<php
sql="get * from selected store"
foreach{item in selected store}{
sql="get name for looped item"
sql="get all admins"
echo"all given info in td"
if{the item has not been processed by a admin}{
<from method="post">
<select name="adminchange" onchange="submit()">
<option value="null">not processed</option>
foreach(for each admin make a option){
<option value="admin email">admin name</option>
};
</select>
</form>
}else{
echo 'the name of the admin that processed it';
};
};
if (isset($_POST["chosen_admin"])) {
$admin = the admin it was changed to;
$productid = product where the admin was change;
$sql = "UPDATE products SET admin = '$admin' WHERE product_id='$productid'";
$stmt = $conn->prepare($sql);
$stmt->execute();
};?>
以下是我在我的网站上使用的代码(这是真正的代码,所以如果你看到错误,请告诉我,所有提示都是受欢迎的,因为这是我正在研究的一个外容。) :
<form method="POST" >
<select name="winkel">
<option value="1">flowerpower amsterdam</option>
<option value="2">flowerpower den Haag</option>
<option value="3">flowerpower Rotterdam</option>
</select>
<input type="submit" name="store" id="submit" value="nu bestellen" />
</form>
<table border="1">
<tr>
<th><p>artikel</p></th>
<th><p>aantal</p></th>
<th><p>afhaler</p></th>
<th><p>afhaal tijd</p></th>
<th><p>afgehandeld door</p></th>
</tr>
<?php
if (isset($_POST["store"])) {
$sql = "SELECT * FROM verkocht WHERE locatie_ophalen = ". $_POST["winkel"] ;
} else {
$sql = "SELECT * FROM verkocht WHERE locatie_ophalen = 1";
}
$result = $conn->query($sql);
foreach($result as $verkocht){
$sql = "SELECT product_naam FROM producten WHERE product_id = ?";
$stmt = $conn->prepare($sql);
$stmt->execute(array($verkocht["product_id"]));
$gegevens = $stmt->fetch(PDO::FETCH_ASSOC);
$sql = "SELECT * FROM users WHERE medewerker = 1";
$admins = $conn->query($sql);
echo '<tr><td>'. $gegevens["product_naam"]. '</td>
<td>'. $verkocht["verkocht_aantal"].'</td>
<td>'. $verkocht["verkocht_klant"].'</td>
<td>'.$verkocht["tijd_ophalen"].'</td>
<td>';
if($verkocht["medewerker_verwerkt"] == 0){
echo'<form method="POST"><select name="chosen_admin" onchange="submit()">
<option value="null">nog niet verwerkt</option>';
foreach($admins as $admin){
echo'<option value="'. $admin["email"].'">'. $admin["voornaam"].' '. $admin["achternaam"].'</option>';
};
}else{
echo $verkocht["medewerker_verwerkt"];
};
echo '</select></form>';
echo '</td></tr>';
};
if (isset($_POST["chosen_admin"])) {
$medewerker = $_POST["chosen_admin"];
$verkoopid = $verkocht["verkocht_id"];
$sql = "UPDATE verkocht SET medewerker_verwerkt = '$medewerker' WHERE verkocht_id='$verkoopid'";
$stmt = $conn->prepare($sql);
$stmt->execute();
};?>
</table>