如何循环遍历一个“如果”语句,直到有输出


How to cycle through an "if" statement until there is output?

我正在制作一个表。对于每一行,我想循环遍历if语句,直到它为真,然后停止(这样每行都包含一个元素)。有没有一种不使用goto的方法来做到这一点?下面是我到目前为止编写的代码:

<?php do { ?>
<td><?php
  if((is_numeric(strpos($row_rsResults['Location'], $varLoc_rsResults)) || $row_rsResults['Location']=="USA") && is_numeric(strpos($row_rsResults['Age_group'], $varAge_rsResults)) && is_numeric(strpos($row_rsResults['Type'], $varTyp_rsResults))){ 
  echo $row_rsResults["Organization"];
  }
  //else go back through if statement until $row_rsResults["Organization"] is echoed
  ?>&nbsp;</td>
编辑:

下面是我所拥有的数据的一个例子,以及我希望如何显示它,如果它有帮助的话:

$row_rsResults['Location']="DC, FL"
$varLoc_rsResults="DC"
$row_rsResults['Age_group']="c, d, e"
$varAge_rsResults="d"
$row_rsResults['Type']="1, 2, 3"
$varTyp_rsResults="1"
$row_rsResults['Organization']="Organization Name"

每个$row_rsResults的信息存储在数据库中,每个$varXxx_rsResults都有一个通过GET从另一个页面访问的值。理想情况下,我希望表最终看起来像这样:

<table>
  <tr>
<td>Organization Name 1</td>
</tr>
<tr>
<td>Organization Name 2</td>
</tr>
<tr>
<td>Organization Name 3</td>
</tr>
//etc.
</table>

没有空行或有多个条目的行

你可以使用for循环来解决这个问题,

<?php do { ?>
<td><?php
for ($i=1;$i<=3;$i++)
{
if((is_numeric(strpos($row_rsResults['Location'], $varLoc_rsResults)) || $row_rsResults['Location']=="USA") && is_numeric(strpos($row_rsResults['Age_group'], $varAge_rsResults)) && is_numeric(strpos($row_rsResults['Type'], $varTyp_rsResults))){ 
echo $row_rsResults["Organization"];
$i=4;
}
else {
$i=1;
}
}
?>&nbsp;</td>