Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更改mysql查询结果集的数组索引_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

Php 更改mysql查询结果集的数组索引

Php 更改mysql查询结果集的数组索引,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,这是mymysql表 id name ssn phone email** 1 Asok 5466 9865893265 asok@gmail.com 2 Sokan 7856 9562358965 sakan@gmail.com ...... ..... 当我使用select查询时,我将得到如下结果: Array ( [0] => Array ( [id] => 1 [name] => Asok [sin] =&g

这是mymysql表

id  name   ssn    phone       email**  
1   Asok   5466   9865893265  asok@gmail.com  
2   Sokan  7856   9562358965  sakan@gmail.com
......  
.....
当我使用select查询时,我将得到如下结果:

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”字段(这对此人来说是唯一的no)

您希望这样吗

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

$newArray = array();
foreach ($results as $row)
{
   $newArray[$row['sin']] = $row;
}

这个链接也在讨论中

functions map_array($key_field, $value_field) and map($key_field, $value_field)
that return a map (dictionary) from the result set

尝试mySQL索引提示语法

您可以使用foreach循环创建新数组,其中sin为key@chandresh_cool-是否可以使用查询本身获取它?@user2609417使用查询是不可能的。不可能使用sqlI知道这一点。但我需要使用这个查询本身