只从MySQL获取字段名

发布于 2024-12-26 15:12:58 字数 265 浏览 3 评论 0原文

现在,当我运行以下查询 SELECT * FROM table 时,我得到以下响应

array(1) {
  [0]=>
  array(36) {
    [0]=>
    string(5) "31764"
    ["id"]=>
    string(5) "31764"
    ...
  }
  ...
}

正如您所看到的,我得到了 2 个相同的数据(“0”和“id”)。有什么办法只能获取“id”而不是“0”吗?

Right now when I run the following query SELECT * FROM table I get the following response

array(1) {
  [0]=>
  array(36) {
    [0]=>
    string(5) "31764"
    ["id"]=>
    string(5) "31764"
    ...
  }
  ...
}

As you can see I am getting 2 of the same data ("0" and "id"). Is there any way I can only get "id" and not "0"?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

行至春深 2025-01-02 15:12:58

查看mysql_fetch_array()<的文档/a>,第二个参数允许您指定返回哪种类型的数组:

要获取的数组类型。它是一个常量,可以采用以下值:MYSQL_ASSOC、MYSQL_NUM 和 MYSQL_BOTH。

或者您可以使用 mysql_fetch_assoc()

Check the documentation of mysql_fetch_array(), the second argument allows you to specify what kind of array to return:

The type of array that is to be fetched. It's a constant and can take the following values: MYSQL_ASSOC, MYSQL_NUM, and MYSQL_BOTH.

Or you could just use mysql_fetch_assoc().

ゃ人海孤独症 2025-01-02 15:12:58

你可以像这样编写sql:
从表中选择“id”
它会回来

you can write the sql just like :
SELECT 'id' FROM table
it wil just return

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文