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 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线