【发布时间】:2015-08-05 02:26:37
【问题描述】:
编辑:这是我的函数中的一个错字导致了我的问题。我输入了 $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
【问题讨论】:
-
你的“Env_Lines”的值是多少?如果它太小,您可能没有任何记录可以检查。
-
这些是函数应检查的最后记录数。所以它总是 1 或更多。
-
@R2D2 你确定 $record_selection 返回一行吗?
-
感谢您让我检查,我发现我在函数中创建了一个类型。 @bassxzero
标签: php mysql function mysqli while-loop