我正在使用文本区域搜索用户可以在一次最多10个手机号码中键入的号码。当我尝试使用2个数字进行测试时,如果我键入第一个数字,它在我们的数据库中有其配置文件,则输出是正确的。但是如果我用数字键入第一个值,而数字在我们的数据库中没有它的配置文件,则输出变得不正确,并且它不会循环第二个值。我收到错误的非法偏移字符串。这个案子可以帮助我吗?提前谢谢
if (isset($_POST['search']) && $_POST['search'] == 'Search') {
$police = new police();
$user = $_SESSION['username'];
$searchuser = $_POST['searchby'];
$_SESSION['searchby'] = $_POST['searchby'];
$param = explode("\n", trim($_POST['info']));
for ($i = 0; $i < count($param); $i++) {
$param[$i] = str_replace(array("\r", "\n", "\r\n"), "", $param[$i]);
}
try {
if ($_POST['searchby'] == 'select') {
throw new Exception("Please select your identity search");
}
} catch (Exception $ex) {
$errmsg = $ex->getMessage();
$tbs->VarRef['searchFail'] = 'true';
$tbs->VarRef['searchFailMsg'] = $errmsg;
$user = $_SESSION['username'];
}
if (isset($param) && $_POST['searchby'] == 'msisdn') {
$ptrnmsisdn = "/^(\+?6?01)[0|1|2|3|4|6|7|8|9]\-*[0-9]{7,8}$/";
for ($i = 0; $i < count($param); $i++) {
$param[$i] = preg_replace("/^(6)(\d+)/", "$2", $param[$i]);
}
try {
if (empty($param)) {
throw new Exception("Please enter your search");
} else {
foreach ($param as $item) {
if (!preg_match($ptrnmsisdn, $item)) {
throw new Exception("Please enter correct mobile number");
}
}
}
$tbs->LoadTemplate('msisdnprofile1.html');
//$_SESSION["msisdnlist"] = $police->getSubsInfo($param[0],$searchmsisdn);
try {
$searchResult = array();
foreach ($param as $paramValue) {
$search = "NRIC";
$msisdnList = $police->getSubsInfo($paramValue, $search);
$searchResult[$paramValue] = $msisdnList;
}
} catch (Exception $ex) {
$searchResult[$paramValue] = $ex->getMessage();
}
$listMsisdn = "";
$arryTemp = array();
foreach ($searchResult as $searchValue => $subValue) {
array_push($arryTemp, $searchValue);
$listMsisdn .= '<div>
<h3>' . $searchValue . '</h3>
<table>
<thead>
<tr>
<th width="300">Mobile Number</th>
<th width="300">Status</th>
<th width="300">View</th>
</tr>
</thead>
<tbody>
';
$listMsisdn .= '<tr>
'。 $ subValue ['msisdn']。 “ '。 $ subValue ['Reg_Status']。 “ “;
$listMsisdn .= ' </tbody>
</table>
';
}
$_SESSION['$searchValue'] = $searchValue;
$_SESSION['$listMsisdn'] = $listMsisdn;
$_SESSION['$listOfSearchValue'] = $arryTemp;
$tbs->Show();
die();
} catch (Exception $ex) {
$user = $_SESSION['username'];
$errmsg = $ex->getMessage();
$tbs->VarRef['searchFail'] = 'true';
$tbs->VarRef['searchFailMsg'] = $errmsg;
}
}
}
答案 0 :(得分:0)
您在整个try/catch
循环周围拥有foreach
。因此,如果任何参数中存在错误,则循环将在该点停止。您需要将其放在getSubsInfo()
的调用周围,这样您就可以继续使用$param
数组的其余部分进行循环。
$searchResult = array();
$search = "NRIC";
foreach ($param as $paramValue) {
try {
$msisdnList = $police->getSubsInfo($paramValue, $search);
$searchResult[$paramValue] = $msisdnList;
} catch (Exception $ex) {
$searchResult[$paramValue] = $ex->getMessage();
}
}