Archive

Archive for the ‘Programming’ Category

Create brick wall table using PHP

September 14th, 2009 aznxfrost No comments

Brick Wall

Heres the code to create a table that looks like brick wall

Users can specify the rows and columns

spent 20 mins…here it is :)

Works perfect in IE, however, under firefox there will be an extra row at top, no idea how that can avoided since if the row is deleted the cell widths wont be consistant.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>BRICK WALL CHALLENGE BY AZNXFROST@EYNY</title>
<style type=”text/css”>
<!–
body,td,th {
font-family: Geneva, Arial, Helvetica, sans-serif;
}
–>
</style></head>
<body>
<h1>BRICK WALL CHALLENGE BY AZNXFROST@EYNY</h1>
<?
$tablewidth = (int)$_GET['width'];
$row = (int)$_GET['row'];
$col = (int)$_GET['col'];
if($tablewidth==0)$tablewidth=600;
if($row==0)$row=5;
if($col==0)$col=5;
$col2 = $col*2;
$celw = round($tablewidth / $col2, 0) ;
$celw2 = $celw * 2;

echo(“<table width=\”{$tablewidth}\” border=\”1\”>\n”);
echo(“<tr style=\”display: ;\”>\n”);
for ($j = 1; $j <= $col2; $j++) {
echo(“<td width=\”{$celw}\”></td>\n”);
}
echo(“</tr>\n”);
for ($i = 1; $i <= $row; $i++) {
echo(“<tr>\n”);
if($i % 2 == 0){
for ($j = 1; $j <= $col2/2+1; $j++) {
if($j == 1 or $j == $col2/2+1){
echo(“<td width=\”{$celw}\”>&nbsp;</td>\n”);
}else{
echo(“<td colspan=\”2\” width=\”{$celw2}\”>&nbsp;</td>\n”);
}
}
}else{
for ($j = 1; $j <= $col2/2; $j++) {
echo(“<td colspan=\”2\” width=\”{$celw2}\”>&nbsp;</td>\n”);
}
}
echo(“</tr>\n”);
}
echo(“</table>”);
?>

<form method=”GET”>
<p>Width:
<input type=”text” name=”width” id=”width” value=”<?=$tablewidth?>”/>
<br />
Row:
<input type=”text” name=”row” id=”row” value=”<?=$row?>”/>
<br />
Column:
<input type=”text” name=”col” id=”col” value=”<?=$col?>”//>
</p>
<p>
<input type=”submit” name=”button” id=”button” value=”MAKE SEXY BRICK WALL” />
</p>
</form>
</body>
</html>

Categories: Programming Tags: