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 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 用ADS设计一款的射频功率放大器