Skip to content

Commit

Permalink
解决部分内容被回退问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lhs168 committed Dec 23, 2017
1 parent d921e01 commit edace6a
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/Fasim/Db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,19 @@ public function scalar($field) {
/**
* 根据指定的字段,从查询结果中取得一个pair关联数组
*
* @param string $key_field 用作数组key的字段
* @param string $value_field 用作value的字段
* @param string $keyField 用作数组key的字段
* @param string $valueField 用作value的字段
* @return array
*/
//???
public function pairs($key_field, $value_field) {
public function pairs($keyField, $valueField) {
$result = $this->find();
$ret = array();
foreach ($result as $row) {
if ($key_field == null || !isset($row[$key_field])) {
$ret[] = $row[$value_field];
foreach ($result as $item) {
if ($keyField == null || !isset($item->$valueField)) {
$ret[] = $item->$valueField;
} else {
$key = $row[$key_field];
$val = $row[$value_field];
$key = $item->$keyField;
$val = $item->$valueField;
$ret[$key] = $val;
}

Expand All @@ -120,16 +119,15 @@ public function pairs($key_field, $value_field) {
/**
* 获取全部数据,结果是以数据行中指定的字段为key的关联数组
*
* @param string $key 作为key的字段
* @param string $keyField 作为key的字段
* @return array
*/
//???
public function dict($key_field) {
public function dict($keyField) {
$result = $this->find();
$ret = array();
foreach ($result as $row) {
$key = $row[$key_field];
$ret[$key] = $row;
foreach ($result as $item) {
$key = $item->$keyField;
$ret[$key] = $item;
}
return $ret;
}
Expand Down

0 comments on commit edace6a

Please sign in to comment.