gpt4 book ai didi

php - 检查标准的功能

转载 作者:行者123 更新时间:2023-11-29 06:26:59 24 4
gpt4 key购买 nike

编辑:是我函数中的错字导致了我的问题。我输入了 $sytem 而不是 $syStem。


我正在尝试将这段代码变成一个函数。

我正在检查客户的最后状态记录。如果每条记录在 Delay 中都有一个 0,那么它是成功的。如果一条或多条记录不是 0,则失败。

但是当每个客户在 Delay 中的数字不同于 0 时,我都获得了成功。我做错了什么?

<?php
//Shows if one or more replications have a delay
function delay_total($conn, $customer, $sytem){
$sql_customer = "SELECT Cust_ID, Cust_Name, Env_Lines FROM `Customer` WHERE Cust_Name = '$customer' LIMIT 0,1";
//echo $sql_customer;
$customer_selection = mysqli_query($conn,$sql_customer);
$customer_row = mysqli_fetch_assoc($customer_selection);
$env_lines = $customer_row["Env_Lines"];
$cust_id = $customer_row["Cust_ID"];
//echo $cust_id;
$sql_last_records = "SELECT Delay FROM $system WHERE Cust_ID = $cust_id ORDER BY Time DESC LIMIT $env_lines";
//echo $sql_last_records;
$record_selection = mysqli_query($conn, $sql_last_records);

$count = 0;
while($source_row = mysqli_fetch_array($record_selection)){
if ($source_row['Delay'] == 0 ) {
$count++;
}
}
if($count != mysqli_num_rows($record_selection)) {
echo "Fail";
} else echo "Success";
}

?>

gist.github.com/R2D2-05/da1cc473a68dccc3be35

最佳答案

我认为,如果您的查询返回零条记录,那么您也会获得成功(因为 $count 等于 0 也等于 0 记录。

您可以通过验证至少找到一条记录来解决此问题,更改:

if($count != mysqli_num_rows($record_selection)) {

if($count != mysqli_num_rows($record_selection) || mysqli_num_rows($record_selection) == 0) {

关于php - 检查标准的功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30407292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com