dqwcdqs358367 2017-04-05 06:50
浏览 67
已采纳

使用php在mysql表中显示表中的数据

I have a table named revenue in a mysql database, i need to display the columns and data in the form if a table. So far i'm simply echoing the data in the below code. Help is appreciated.

 <?php 

    include('adodb/adodb.inc.php');
    echo 'To See existing records';
    $db=NewADOConnection('mysql');$db->Connect("127.0.0.1", "vpp", "abcd", "vpp");


    $sql="select * from revenue";
    $result = $db->Execute($sql);
    if ($result === false) die("failed2");
    $records=array();
    $count=$result->RecordCount();
    echo "Total Records Found :".$count."<br>";
    if($count > 0) {
        for ($x=0;$x<$count;$x++) {
            $offerId=$result->fields[0];
            $affId=$result->fields[1];
            $status=$result->fields[2];
            $deduction=$result->fields[3];


            echo "OfferId:".$offerId." and AffId:".$affId." with deduction %:".$deduction." status=".$status."<br>"; // Need this data to be dispalyed in a table
            $rec=array("offerId"=>$offerId,"affiliate_id"=>$affId,"status"=>$status, "deduction"=>$deduction);
            array_push($records,$rec);
            $result->MoveNext();
            }
     }
?>
  • 写回答

1条回答 默认 最新

  • dongque4778 2017-04-05 07:17
    关注

    Loop your $records array and echo the the rows in html table like this

        <table>
        <thead>
            <tr>
                <th>
                    OfferId
                </th>
                <th>
                    Affiliate_id
                </th>
                <th>
                    status
                </th>
                <th>
                    deduction
                </th>
    
            </tr>
        </thead>
        <tbody>
        <?php
        foreach($records as $row)
        {
        ?>
    
        <tr>
            <td>
            <?php echo $row['offerId']; ?>
            </td>
            <td>
            <?php echo $row['affiliate_id']; ?>
            </td>
            <td>
            <?php echo $row['status']; ?>
            </td>
            <td>
            <?php echo $row['deduction']; ?>
            </td>
        </tr>
    
    
        <?php
        }
        ?>
    
        </tbody>
        </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条