我需要帮助这个问题的家伙
我有一个4列的表。 no, name, address, phone
。这种情况是在我删除一个数据之后,我必须减少列no
以及我删除的数据量。
上次我使用vb.net制作程序时,我可以这样做。我使用这个代码我可以做得很好
Dim ab As Integer
ab = lvrak.Items(i).SubItems(4).Text
Dim stok As New SqlClient.SqlCommand("Update tbl_barangluar set jumlah_barang=jumlah_barang - '" & ab & "' where kode_barang='" & _
lvrak.Items(i).SubItems(0).Text & "'")
stok.Connection = koneksi
stok.ExecuteNonQuery()
但现在我需要在php函数中这样做。我真的不知道该怎么做。
我试着做ex. update temp5 set no='$no' - 1
并且进展不顺利。有人请帮助我
这是我的试用PHP
<?php
include("../../Connections/koneksi.php");
$no= $_POST['no_check'];
// Attempt insert query execution
$sql = "DELETE FROM temp5 WHERE no='$no'";
if(mysqli_query($db, $sql)){
echo "Records were deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}
// Close connection
mysqli_close($db);
?>
<?php
include("../../Connections/koneksi.php");
$no= $_POST['no_check'];
// Attempt insert query execution
$sql = "alter table temp5 auto_increment = 1";
if(mysqli_query($db, $sql)){
echo "Records were deleted successfully.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}
// Close connection
mysqli_close($db);
?>
<?php
include("../../Connections/koneksi.php");
$no= $_POST['no_check'];
$min = 1;
// Attempt insert query execution
$sql = "UPDATE temp5 SET no=no -1 where no";
if(mysqli_query($db, $sql)){
echo "Records inserted successfully.";
} else{
echo "Records inserted failed ";
}
mysqli_close($db);
?>
&#13;
我会在删除功能之前和之后添加一张图片。
问题出在那里。我试图限制他们,但更多的是恐怖。
在第一张图片中包含删除前的所有数据。我会用no 4
删除数据。结果如图2所示。结果错误..结果必须是1,2,3,4
答案 0 :(得分:0)
您需要在删除success
UPDATE temp5 SET no=no -1
PHP:
<?php include("../../Connections/koneksi.php");
$no= $_POST['no_check'];
$sql = "DELETE FROM temp5 WHERE no='$no'";
if(mysqli_query($db, $sql)){
$sql1 = "UPDATE temp5 SET no=no -1";
mysqli_query($db, $sql1);
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($db);
}