Centring a php/mysql table
Posted: Wed Nov 08, 2006 5:53 pm
how would i go about centring this table to a page, iv tryed putting in <div align="center"> just under 'defining html table' and </div> under 'echo $table;' can some one tell me where im going rong,
thanks clint
thanks clint
Code: Select all
include("Connect.php");
$query="SELECT p.PartNumber, p.Description, (p.IncTax*1.3) AS Price FROM `price list` p WHERE p.CategoryID = '100' order by PartNumber";
$data_resource=mysql_query($query,$connection);
//Defining HTML table
$rowcount = 0;
$table="<table cellspacing=0 cellpadding=0 width=400>";
while ($row = mysql_fetch_array($data_resource)) {
$rowcount++;
$table.=sprintf('<tr bgcolor="%s"><td>'.$row['Description'].'</td>', $rowcolor);
$table.=sprintf('<td>'.$row['Price'].'</td></tr>', $rowcolor);
$rowcolor = $rowcount % 2 == 0 ? "#FFFFFF" : "#C4DAFA";
}
//Closing HTML table
$table.="</table>";
//Displying table and closing mysql database if not need
echo $table;
mysql_close();