Mongo db游标计数不能正常工作?

时间:2017-04-04 07:38:28

标签: php arrays mongodb mongodb-php

我在php中编写了以下代码,并使用mongo db作为数据库

(?i)(?:b|[li]3)[0o]{2}

取得" studentList"来自broadcastTbl表,$projection = array("broadcast_id" => 1,"studentList" => 1); $query = array('broadcast_id'=> $broadcast_id); $count = $this->collection->find($query)->count(); $cursor = $this->collection->find($query,$projection); $result = array(); foreach($cursor as $row) { $idstring = trim($row["studentList"]); $idstring = preg_replace('/\.$/', '', $idstring); $idarray = explode('|', $idstring); foreach($idarray as $studentId) { $this->StudentCollection = $this->db->studentTbl; $StudentCursor= $this->StudentCollection->find(array("student_id" => $studentId)); if($StudentCursor->count() > 0) { foreach ($StudentCursor as $k => $srow) { array_push($result, $srow); } } else { array_push($result, array("datanotfound"=>1)); } } } return json_encode($result); 有" 5042 | 5043 | 5044"作为studentTbl的学生ID的值。现在我试图通过在" |"的基础上逐个拆分来获取相应的学生详细信息。之后我试图将它们推入数组$ result。

始终显示$idstring为" 1"并且永远不要输入else块,即使find()查询无法找到记录,然后它显示输出为[],即它始终保持在if语句!!!

请帮我跟踪代码中的错误并有效地编写代码!!!

0 个答案:

没有答案