我在mysql数据库中有一个名为revenue的表,我需要在表格中显示表格中的列和数据。到目前为止,我只是回显下面代码中的数据。感谢帮助。
<?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();
}
}
?>
答案 0 :(得分:1)
循环你的$records
数组,并像这样回显html表中的行
<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>