The following code works fine. In the class file, there are four arguments for the function setRowCol($r,$c, $v, $pa) in which $pa is an argument for padding which is passed inside the function startCol($p). But it doesn't work when i set padding like the following
public function startCol($p) {
$tab= "<td Style='border:4px solid black; padding:'".$p."'px;>";
return $tab;
}
and works fine if I give the value directly like
$tab= "<td Style='border:4px solid black; padding:110px;>";
But I would like to keep padding value as an argument. Is there a solution for this?
Full Class File
class CreateTable {
public $rows;
public $cols;
public $val = array();
public $pad;
public function setRowCol($r,$c, $v, $pa) {
$this->rows = $r;
$this->cols = $c;
$this->val = $v;
$this->pad = $pa;
echo $this->startTable();
for($i=0; $i<$this->rows && $i<sizeof($this->val); $i++) {
echo $this->startRow();
for($j=0; $j<$this->cols && $j<sizeof($this->val); $j++) {
echo $this->startCol($this->pad);
echo $this->val[$j];
echo $this->endCol();
}
echo $this->endRow();
}
echo $this->endTable();
}
function startTable() {
$tab = "<table Style='border:1px solid black';>";
return $tab;
}
function endTable() {
$tab= "</table>";
return $tab;
}
function startRow() {
$tab= "<tr Style='border:1px solid black';>";
return $tab;
}
function endRow() {
$tab= "</tr>";
return $tab;
}
public function startCol($p) {
$tab= "<td Style='border:4px solid black; padding:'".$p."'px;>";
return $tab;
}
function endCol() {
$tab= "</td>";
return $tab;
}
}
?>
File
<?php
include "CreateTable.php";
$arr = array("Jan", "feb","mar", "apr");
$tab = new CreateTable();
echo $tab->setRowCol(3,10, $arr, 110);
?>