Jan*_*ela -2 php mysql while-loop
我有一个PHP脚本来检查一些数据的可用性.我从外部jquery调用这个脚本.jquery运行正常.这是我的PHP:
<?php
$avares = checkAva($fi_nm, $tbl_nm, $txtval);
echo $avares;
function checkAva($field, $table, $curval) {
$avres = mysql_query("SELECT " . $field . " FROM " . $table . "") or die("query failed");
while ($a_row = mysql_fetch_array($avres)) {
$dbval = $a_row[$field];
if ($curval == $dbval) {
return "no";
} else {
return "yes";
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
$ curval是来自外部jquery的变量.我的问题是虽然数据库中有很多条目,但while循环似乎只运行一次.我用一个整数变量检查它,而while循环似乎只运行一次.你能帮我解决一下吗?
看看你的代码.
while ($a_row = mysql_fetch_array($avres)) {
$dbval = $a_row[$field];
if ($curval == $dbval) {
return "no";
} else {
return "yes";
}
}
Run Code Online (Sandbox Code Playgroud)
你使用了return,如果它返回true,那么也会根据你的需要返回更改.return语句立即结束当前函数的执行