嗨所以我做了一个查询,当我尝试循环出结果时,它会一遍又一遍地循环出相同的变量。这不是一个无限循环,并且由于数据的原因,很难判断它是否循环了正确的次数。我正在尝试做的是:从客户表中选择所有不同的 customer_uid,其中 start_cycle_uid (来自 start_cycle 表)具有相同的 customer_home id 和相同的 start_date 传入。所以我会得到每个客户之一在该开始日期属于那个 customer_home。我得到的是相同 customer_uid 的列表。我的逻辑错了吗?
$homeQuery=$DB->prepare("select distinct customer_uid from customers
where start_cycle_uid =
(select uid from start_cycles
where customer_home_uid=".$DB->quote_smart($_REQUEST['homeid'])."
and start=".$DB->quote_smart($_REQUEST['start']).")");
$homeResult=$DB->query($homeQuery);
$homeRow=$DB->fetchArray($homeResult);
if ($DB->numRows($homeResult) > 0) {
for ($x=0; $x<=$DB->numRows($homeResult); $x++){
echo $homeRow['customer_uid']."<br />";
}
}
更新:当前代码如下所示:
$homeQuery=$DB->prepare("select distinct customer_uid from customers
where start_cycle_uid =
(select uid from start_cycles
where customer_home_uid=".$DB->quote_smart($_REQUEST['homeid'])."
and start=".$DB->quote_smart($_REQUEST['start']).")");
$homeResult=$DB->query($homeQuery);
while($row = $DB->fetchArray($homeResult))
{
echo $row['customer_uid']."<br />";
}
这现在陷入了一个无限循环。