【发布时间】:2014-09-08 18:54:30
【问题描述】:
我有一些代码可以在 while 循环中回显一行文本。但我不希望它作为一个循环,并且如果没有 while() 似乎无法让它工作。我的代码如下 - 我怎样才能让回声只打印一次?
while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {
do($row['InGarage'] == $comp and $row['BeingServiced'] == $unco and $row['ReadyForCollection'] == $unco) {
echo "Vehicle is in Garage<br />";
}
do($row['InGarage'] == $comp and $row['BeingServiced'] == $comp and $row['ReadyForCollection'] == $unco) {
echo "Vehicle is being serviced<br />";
}
do($row['InGarage'] == $comp and $row['BeingServiced'] == $comp and $row['ReadyForCollection'] == $comp) {
echo "Vehicle is ready for collection<br />";
}
}
更新:使用 if
while($row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC)) {
}
if($row['InGarage'] == $comp and $row['BeingServiced'] == $unco and $row['ReadyForCollection'] == $unco) {
echo "Vehicle is in Garage";
}
if($row['InGarage'] == $comp and $row['BeingServiced'] == $comp and $row['ReadyForCollection'] == $unco) {
echo "Vehicle is being serviced";
}
if($row['InGarage'] == $comp and $row['BeingServiced'] == $comp and $row['ReadyForCollection'] == $comp) {
echo "Vehicle is ready for collection";
}
【问题讨论】:
-
除了非常粗鲁之外,Marc 是对的。这可以通过doing and if语句来实现。
-
当我使用 if 语句时,什么都不会打印,而与循环一样,它会打印很多次......我将把我的新代码放在问题的正文中
-
When I use an if statement, nothing prints;因为您将所有内容都放在循环体之外:) -
在您更新的代码中,您甚至在到达
if()语句之前就关闭了循环。 -
@the_pete 我不想让它循环播放,这是我的问题
标签: php