doukun8670 2015-07-08 15:07
浏览 28

如何使用mysql将id的所有列值回显到行中

I am on the way to create a webform for education related activity. My mysql table looks like this

+----+--------+---------+-----------+---------+-----------------------------
| id |schlname| trname  | pay  |oa |gross|trname2|pay2|oa2|gross2| -----etc
+----+--------+---------+-----------+---------+-----------------------------
|  1 |Greatedn|  Bredier| 1000 | 25|1025|Pastiur |1000| 25|1025  |
   2 |Meritedn|  Paskin | 1000 | 25|1025|Blazer  |1000| 25|1025  |
+----+--------+---------+-----------+---------+----------------------------

I need to take report using php query using echo statement. My expected report should be like this

+----+--------+---------+-----------+-------
| id |schlname| trname  | pay  | oa |gross |
+----+--------+---------+-----------+-------
|  1 |Greatedn|  Bredier| 1000 | 25 |1025  |
                 Pastiur |1000 | 25 |1025  |
                 etc...
                 etc...
   2 |Meritedn|  Paskin | 1000 | 25 |1025  |
                 Blazer |1000  | 25 |1025  |
                 etc...
                 etc..

Your valuable ideas are expected to complete my study

  • 写回答

2条回答 默认 最新

  • duan20081202 2015-07-08 15:21
    关注

    This is untested, but I'd go somewhere along these lines, maybe a double for loop if you want to make it look pretty

            require "conn.php";
            $sql = $dbh->prepare("SELECT * FROM yourtablename WHERE 1");
            $sql->execute();
            $data_storage = $sql->fetch_all();
            for($i = 0; $i < $data_storage->rowCount(); $i++) {
                echo $data_storage[$i];
            }
    

    Let me know if this answers your question. Not quite sure if this is what you're asking for.

    评论

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算