I'm trying to make a function which allows for dynamic creation of a table, however many rows and columns large. I've made the function, and the table generates, but something is wrong in my loop.
In my example, I'm trying to put a form into a nice simple, 2 across, 5 down box.
I want my table to look like:
Description1 | Field1
Description2 | Field2
Description3 | Field3
Button1 | Button2
HiddenBox |
However, it comes out like:
Field1 | Field2 | Field3 | Button1 | Button2
Description1
Description2
Description3
HiddenBox
This is my register.php file (the one which passes the data to the function):
<?php
require_once ("GlobalConf.php");
require_once ("include/MySQLDbConnect.php");
require_once ("include/BasicFunctions.php");
$connector = new MySQLDbConnect();
$basicDisp = new BasicOutput();
$basicDisp->displayTitleTable ("Register");
echo ("<br>Please enter all information<br><br>\n");
echo ("<form name=\"register\" action=\"submitForm.php\" method=\"POST\">\n");
$basicDisp->displayAdvancedTable ("1", "0", "0", "", "100%", "5", "2", array (
array ( "Desired User Name: ", $basicDisp->makeFormField("text", "username", "", "i000000") ),
array ( "Password: ", $basicDisp->makeFormField("password", "password", "", "i000000") ),
array ( "E-mail address: ", $basicDisp->makeFormField("text", "email", "", "i000000") ),
array ( $basicDisp->makeButton("submit", "Submit Registration", "i000000"), $basicDisp->makeButton("reset", "Reset Form", "i000000") ),
array ( $basicDisp->makeHiddenField("submitType", "register"), "" )
));
echo ("</form>");
?>
This is displayAdvancedTable():
function displayAdvancedTable ($border, $cellpadding, $cellspacing, $class, $width, $rows, $cols, $data)
{
$BigTable = "<table border=\"". $border ."\" cellpadding=\"". $cellpadding ."\" cellspacing=\"". $cellspacing."\" width=\"". $width ."\">";
for ($loopRow = 0; $loopRow < $rows; $loopRow++)
{
$BigTable .= "<tr>\n";
for ($loopCol = 0; $loopCol < $cols; $loopCol++)
{
$BigTable .= "<td align=\"center\">". $data[$loopRow][$loopCol] ."</td>\n";
}
$BigTable .= "</tr>\n";
}
$BigTable .= "</table>\n";
echo $BigTable;
}
This is makeFormField():
function makeFormField ($type, $name, $value, $class)
{
$Field = "<input type=\"". $type ."\" class=\"". $class ."\" name=\"". $name ."\" value=\"". $value ."\">";
echo $Field;
}
This is makeButton():
function makeButton ($type, $value, $class)
{
$Field = "<input class=\"". $class ."\" type=\"". $type ."\" value=\"" .$value ."\">";
echo $Field;
}
And this is makeHiddenField():
function makeHiddenField ($name, $value)
{
$Field = "<input type=\"hidden\" name=\"". $name ."\" value=\"". $value ."\">";
echo $Field;
}
Any help on this would be appreciated.
Thank you.