简体   繁体   中英

Display data in a table from a mysql table, using php

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();
            }
     }
?>

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM