PHP循环记录集,直到
问题描述:
在PHP中,我如何循环mysql记录集,直到我发现我需要的标准?PHP循环记录集,直到
它只是:
$sql_result = mysql_query("SELECT * FROM table", $db);
while ($rs = mysql_fetch_array($sql_result) && $done == 0) {
if (this == that) { $done = 1; }
}
答
if (this == that) { break; }
只要跳出循环,它会停止运行,并与其余代码矣。
答
的立即明显的答案是:
$sql_result = mysql_query("SELECT * FROM table", $db);
while ($rs = mysql_fetch_array($sql_result) && $done == 0) {
if (this == that) {
break;
}
}
carry_on();
有什么你可以用你的查询,虽然这样做?为了让它只为你得到正确的结果?你实际上在做什么this == that
条件?
答
就是这么多 - 查看结束该搜索的其他答案。另请考虑调整您的查询以选择您要查找的特定记录。让数据库处理搜索将会更快/更高效。
答
这应该工作,但你也可以这样做:
$sql_result = mysql_query("SELECT * FROM table", $db);
while ($rs = mysql_fetch_array($sql_result)) {
if (this == that) {
break;
}
}