所以我一直试图通过按下该表中创建的按钮来获取一条记录并进行编辑,但老实说,我不知道该怎么做。 Dx任何人都可以帮我这个吗? (是的,我想要为每条记录创建按钮。你知道,所以在表格的每一行的末尾,每条记录都会有它自己的按钮。)
while($rArt = mysqli_fetch_array($sql)){
echo '<tr><td>' . $rArt['ArtID'] . '</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
}
答案 0 :(得分:0)
阅读解决方案中的评论,因为它们非常重要。
while($rArt = mysqli_fetch_array($sql)){
// echo '<tr><td>' . $rArt['ArtID'] . '</td>';
//The above line i removed and added the line below
echo '<tr><td>' .'<a href=\'admin.php?ArtID='.$rArt['ArtID'].'\'>'.$rArt['ArtID'] .'</td>';
echo '<td>' . $rArt['FiliaalID'] . '</td>';
echo '<td>' . $rArt['Productnaam'] . '</td>';
echo '<td>' . $rArt['Inkoopprijs'] . '</td>';
echo '<td>' . $rArt['Voorraad'] . '</td>';
echo '<td>' . $rArt['Min_voorraad'] . '</td>';
$voo = $rArt['Voorraad'];
$minvoo = $rArt['Min_voorraad'];
$nodig = $minvoo * 2 - $voo;
$chosen = $rArt['ArtID'];
echo '<td>' . $nodig . '</td>';
//echo '<td><input type="submit" name="bestel" value="Bestel"></td></tr>';
//removed this as you dont need input button here.
}///Your while loop should close here not in the ent
if(isset($_GET['bestel'])){
$query = mysqli_query($mysql, "
UPDATE artikel a, voorraad v
SET v.voorraad = v.voorraad + '$nodig'
WHERE a.artid = v.artid
AND v.voorraad = '$chosen'");
}
//} I remove this tag as your while loop should close before isset function
答案 1 :(得分:0)
在这种情况下,我不会使用提交,但只是一个建议:
为什么不用这种方式尝试:
<table>
<tr>
<td>Artikel ID</td>
<td> **<a href="bestelpagina/edit/id/1">** </td>
</tr>
</table>
因此,您可以创建一个名为“编辑”的操作,您可以在其中执行更改。