Centring a php/mysql table

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
aussie_clint
Forum Commoner
Posts: 41
Joined: Mon Jul 31, 2006 9:14 am
Location: Brisbane, Australia
Contact:

Centring a php/mysql table

Post by aussie_clint »

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


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();
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

Put align="center" in your table tag.
Post Reply