gpt4 book ai didi

php - MySQL 获取数组添加重复值?

转载 作者:可可西里 更新时间:2023-11-01 06:39:49 27 4
gpt4 key购买 nike

我得到这个:

Array
(
[0] => 1
[id] => 1
[1] => 778613c4344dbc9565c359c1154c6a18
[session] => 778613c4344dbc9565c359c1154c6a18
[2] => fn
[first_name] => fn
[3] => ln
[last_name] => ln
[4] => un
[username] => un
[5] => 016e6128e8ca9dda1b310c364d9b622c
[password] => 016e6128e8ca9dda1b310c364d9b622c
[6] => address
[email] => address
[7] => 100
[permission] => 100
[8] => 10
[year_level] => 10
[9] =>
[department] =>
[10] => Sample
[campus] => Sample
[11] => 0
[logo_url] => 0
)

运行后

$user = mysql_fetch_array(mysql_query("SELECT session FROM users WHERE username='$cookie[username]' AND first_name='$cookie[first_name]' AND last_name='$cookie[last_name]' AND campus='$cookie[campus]' AND id='$cookie[id]'")) 

知道为什么它会这样复制吗?谢谢

编辑:我认为主键是这样做的。关于如何阻止它的任何想法?

最佳答案

如果您没有将结果类型指定为第二个参数,mysql_fetch_array()将默认为 MYSQL_BOTH (quoting) :

By using MYSQL_BOTH (default), you'll get an array with both associative and number indices.


如果这不是您想要的,您必须将第二个参数传递给该函数,以指示您想要的结果类型。

例如,只获取一个以列名作为键的关联数组:

$result = mysql_query("SELECT session FROM users WHERE username='$cookie[username]' AND first_name='$cookie[first_name]' AND last_name='$cookie[last_name]' AND campus='$cookie[campus]' AND id='$cookie[id]'");
$user = mysql_fetch_array($result, MYSQL_ASSOC);


作为旁注:

关于php - MySQL 获取数组添加重复值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9247798/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com