dpc57092 2011-07-18 13:17
浏览 38
已采纳

来自mysql_fetch_array的数组,其中查询选择所有内容并未保存所有值

So, I have a database (With a table called users) that let's users connect accounts, and it goes by their usernumber to find their accounts, let's say (With values):

Usernumber|Username|Email
-------------------------
1 | Justin | email@email.com
2 | Test | test@test.com
2 | Hi | gah@goo.com
1 | Foo | hey@hey.com
1 | Bar | Du@de.com

Now, in PHP, I do:

$stuff = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE usernumber=1"));

Now, I do count($stuff); and it returns 14, all the time, whether I do it with usernumber one or two... I can't figure out the problem, but I was wondering if someone else sees it, or knows something that I don't about how certain files are configured (Limits or something?). I'm using XAMPP to test everything right now.

ALSO, when I do the $stuff in PHPMYADMIN as a SQL in the table, it does return all the values it should.

So question is: What am I missing and how do I get it return all the values and not just 2 rows? (The table has 7 columns).

Thanks, Justin W.

  • 写回答

3条回答 默认 最新

  • doutuo6689 2011-07-18 13:20
    关注

    By default, mysql_fetch_array will return a combined indexed array of columns (0 - 6) and associative array (column_name => value)

    That is why you have 14 values for that row (7 that are numerically indexed, 7 that are associatively indexed).

    Also, you only get one row per function call. 14 is the number of columns (7 * 2), not the number of rows.

    You need to start holding your MySQL result resource in its own variable:

    $result = mysql_query("SELECT * FROM users WHERE usernumber=1");
    

    That way you can call mysql_fetch_array multiple times on that resultset. Also, you can check the number of rows by calling mysql_num_rows($result)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)