我有一个运行的脚本,然后指向一个页面来删除一条记录。我想设置它,所以当记录计数为零时,页面重定向到index.php页面。代码如下:
$sql="SELECT * FROM fbi_with_invoice";
if ($result=mysqli_query($conn,$sql))
{
$rowcount=mysqli_num_rows($result);
printf("There are %d rows remaining.\n",$rowcount);
}
if ($rowcount=0) {
header('refresh:5;url=index.php');
mysqli_free_result($result);
}
$sql = "DELETE FROM fbi_with_invoice ORDER BY personid DESC LIMIT 1";
if ($conn->query($sql) === TRUE) {
header('refresh:5;url=index2.php');
}
$conn->close();
目前$rowcount
给出0,但页面重定向到index2.php。
答案 0 :(得分:1)
问题在于:if ($rowcount = 0)
您使用了赋值运算符而不是==
比较运算符。
$sql="SELECT * FROM fbi_with_invoice";
if ($result=mysqli_query($conn,$sql))
{
$rowcount=mysqli_num_rows($result);
printf("There are %d rows remaining.\n",$rowcount);
}
if ($rowcount == 0) {
header('refresh:5;url=index.php');
mysqli_free_result($result);
}
$sql = "DELETE FROM fbi_with_invoice";
if ($conn->query($sql) === TRUE && $rowcount) {
header('refresh:5;url=index2.php');
}
$conn->close();