Reputation: 63
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();
}
}
?>
Upvotes: 0
Views: 83
Reputation: 12085
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>
Upvotes: 1