0

这是我的mysql表

id  name   ssn    phone       email**  
1   Asok   5466   9865893265  asok@gmail.com  
2   Sokan  7856   9562358965  sakan@gmail.com
......  
.....

当我使用选择查询时,我会得到结果:

Array ( [0] => Array ( [id] => 1 [name] => Asok [sin] => 5466 [phone] => 9865893265 [email] => asok@gmail.com )  [1] => Array ( [id] => 2 [name] => Sokan [sin] => 7856 [phone] => 9562358965 [email] => sakan@gmail.com ) ...)`

我需要得到这个结果

Array ( [5466] => Array ( [id] => 1 [name] => Asok [sin] => 5466 [phone] => 9865893265 [email] => asok@gmail.com )  
[7856] => Array ( [id] => 2 [name] => Sokan [sin] => 7856 [phone] => 9562358965 [email] => sakan@gmail.com ) ...)

使用 sql 查询

这里的索引 5466 和 7856 是字段“ssn”(这是该人唯一的否定)

4

3 回答 3

1

你想要这样吗?

SQL 列名ssn,结果数组索引sin。我写成sin

$newArray = array();
foreach ($results as $row)
{
   $newArray[$row['sin']] = $row;
}
于 2013-07-31T07:01:15.587 回答
0

https://github.com/EllisLab/CodeIgniter/pull/429

正在讨论此链接

functions map_array($key_field, $value_field) and map($key_field, $value_field)
that return a map (dictionary) from the result set
于 2013-07-31T07:15:10.737 回答
0

试试 mySQL 索引提示语法 索引提示语法

于 2013-07-31T08:25:10.270 回答