doudie2693 2012-08-05 11:00
浏览 32

在不使用列名作为ref的情况下回显整个表

Hi I really hope someone can help,

I have a table with one row and multiple column names, one of these being id, I want to echo the whole table without using the column names as reference as these might change and I don’t want to have to go in and change the code if a column gets added or taken away. i.e. I want to SELECT * from table WHERE id=1 then echo the whole table, not including the id column or any column titles.

I’m a bit stumped and not sure where to look for the right answer, hopefully someone can point me in the right direction.

Thanks in advance being trying to get my head around this all weekend.

Brill thanks for all the help got it sorted, for anyone who wants my solution:

    $sql = "SELECT * from nav WHERE id='1'";
    $result = mysql_query($sql);
    $row = mysql_fetch_row($result);
    $i=1;

    while($i<=500)
    {
    echo $row[$i]  . "<br />";
    $i++;
    }
  • 写回答

2条回答 默认 最新

  • dongxin5429 2012-08-05 11:04
    关注

    Use mysqli_result::fetch_row instead of mysqli_result::fetch_array as it will return an indexed array of values.

    Example:

    $result  = $mysqli->query($query)
    $columns = $mysqli->field_count;
    while($row = $result->fetch_row()) {
        for($i = 5; $i < $columns; ++$i)
          echo $row[$i] . ", ";
        echo "
    ";
    }
    

    Edit: updated to start from column 5 as requested in comments

    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥15 对于这个问题的算法代码
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题