php while循环只运行一次 [英] php while loop running only once
问题描述
我有一个 php 脚本来检查一些数据的可用性.我从外部 jquery 调用这个脚本.jquery 运行良好.这是我的 php:
I have a php script for check the availability of some data. I call this script from external jquery. the jquery is running fine. here is my 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";
}
}
}
?>
$curval 是来自外部 jquery 的变量.我的问题是虽然数据库中有很多条目,但 while 循环似乎只运行一次.我用一个整数变量检查了它,而 while 循环似乎只运行了一次.你能帮我解决这个问题吗?
$curval is the variable coming from external jquery. my problem is that the while loop seems to run only once though there are lot of entries in the DB. I checked it with an integer variable and the while loop seems to run only once. can you help me to solve that?
推荐答案
查看您的代码.
while ($a_row = mysql_fetch_array($avres)) {
$dbval = $a_row[$field];
if ($curval == $dbval) {
return "no";
} else {
return "yes";
}
}
您使用了 return,如果它返回 true,则返回 false,然后也返回根据您的需要更改这些.return 语句立即结束当前函数的执行
you have used return, if its true it returns and false then also returns change those according to your needs. The return statement immediately ends execution of the current function
这篇关于php while循环只运行一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!