php - mysql_fetch_array 返回重复数据

标签 php mysql

每次我运行 mysql_fetch_array 时,都会返回一个包含重复值的数组例如

Array
(
    [0] => 1
    [row_id] => 1
    [1] => some text
    [first_field] => some text
    [2] => some text
    [second_field] => some text 
}

但我只想要数组中的单个结果,我试过使用

mysql_fetch_array($data, MYSQL_ASSOC);

但这没有什么区别。

最佳答案

这是 mysql_fetch_array() 的预期功能.如果你不想有“重复项”而只想有关联数组,请使用 mysql_fetch_assoc()相反。

例子:

while ($row = mysql_fetch_assoc($data)) { ... }

关于php - mysql_fetch_array 返回重复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11957541/

相关文章:

php - Laravel Homestead - 配置 php.ini 文件

php - mysqli_real_escape_string 不插入数据库

java - 插入数据库AsyncTask错误

mysql - Now() 上的 Convert_tz 返回错误

php - 如何通过另一个数组的值访问数组值

php - 如何打印 Error 405 Method not allowed to users

mysql - MYSQL 中的连接方式

php - 在mysql中存储以逗号而不是点分隔的浮点值

mysql - SQL 获取比较聚合函数的结果

php - 如何在 Laravel 中编写联合查询?