dongxiusuo9881 2014-09-27 16:25
浏览 29
已采纳

ECHO专栏价值从第3季到最后的PHP [关闭]

i want to echo 3rd column's value up to the last column

i know i can do this by echo $result[3]; echo $result[4]; echo $result[5]; and so on up to the last but is there any way to do it this way echo $result[3] UNTIL $result[last]; ? please help me thanks in advance

  • 写回答

1条回答 默认 最新

  • doukun0888 2014-09-27 16:28
    关注

    You need to return numeric indices from DB query and simple for loop. Notice the MYSQL_NUM flag added:

    while($result=mysql_fetch_array($query, MYSQL_NUM)) {
        for ($index = 3; $index < count($result); $index++) {
           echo $result[$index];
        }
    }
    

    EDIT: An alternative. Use mysql_fetch_assoc and access your data using column names instead of numeric indices. This improves readablity of code as well.

    while ($row = mysql_fetch_assoc($result)) {
        echo $row["userid"];
        echo $row["fullname"];
        echo $row["userstatus"];
    }
    
    mysql_free_result($result);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图