doupingdiao3546 2011-10-24 19:34
浏览 32
已采纳

为什么算数会返回22而不是11?

This is my php script

$result = mysql_query("SELECT * FROM photos WHERE perID=2");
$row = mysql_fetch_array($result);
$a = count($row);                     // or sizeof($row)
echo $a;       //outputs 22 but i expect it to be 11 but why does it output 22 ?

This is the data in mysql.

perID   one    two   three   four    five    six    sev    eit   nine  ten
  2    1.jpg  2.jpg  3.jpg   4.jpg   5.jpg  6.jpg  7.jpg  8.jpg  9.jpg 10.jpg

I expect it to be 11 but surprisingly its 22. Could anyone explain me why? Does it also include the 'one' 'two' (the column names) stuff too in the count function ? because it would be 22, if only if it includes them.

But it should not include the column part of table as they are headers right? please help me with these Any help is greatly appreciated

also please give me a link or the way to achieve 11 as result

  • 写回答

5条回答 默认 最新

  • donglie7778 2011-10-24 19:37
    关注

    mysql_fetch_array() by default returns a combined associative AND indexed array structure.

    SELECT a,b,c FROM table
    

    will produce a row array of

    $row = array(0 => 'value of a', 'a' => 'value of a', 1 => 'value of b', etc...);
    

    You can force it to do one or the other by specifying the optional fetch_mode parameter:

    $row = mysql_fetch_array($result, MYSQL_BOTH); // default mode
    $row = mysql_fetch_array($result, MYSQL_ASSOC); // same as mysql_fetch_assoc: associative array
    $row = mysql_fetch_array($result, MYSQL_NUM); // same as mysql_fetch_row: indexed array
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。