Rappa
08-05-2007, 04:32 AM
ugh i have such a headache from this. someone please give me some help:
its a basic table gen, im a novice coder, im doing my best, i tried this far without seeking any help but im out of ideas. heres my code:
<?php
$table = "<table";
$tableclose = ">";
$tdopen = "<td>";
$tdclose = "</td>";
$tropen = "<tr>";
$trclose = "</tr>";
$endtable = "</table>";
if ($cellpadding != "") {
$padding = " " . "cellpadding" . "=" . "\"" . $cellpadding . "\"";
}
else {
$padding = "";
}
if ($cellspacing != "") {
$spacing = " " . "cellspacing" . "=" . "\"" . $cellspacing . "\"";
}
else {
$spacing = "";
}
if ($bordersize != "") {
$border = " " . "border" . "=" . "\"" . $bordersize . "\"";
}
else {
$border = "";
}
if ($width != "") {
$tablewidth = " " . "width" . "=" . "\"" . $width . "\"";
}
else {
$tablewidth = "";
}
if ($bordercolor != "") {
$borderc = " " . "bordercolor" . "=" . "\"" . $bordercolor . "\"";
}
else {
$borderc = "";
}
if ($bgcolor != "") {
$backgroundc = " " . "bgcolor" . "=" . "\"" . $bgcolor . "\"";
}
else {
$backgroundc = "";
}
$tableopen= $table . $padding . $spacing . $border . $tablewidth . $borderc . $backgroundc . $tableclose;
if ($submit == "Generate!") {
$result = $tableopen . "\n" .
$i = 0;
for ($i = $rows; $i > 0; $i++) {
echo $tropen;
for ($i = $columns; $i > 0; $i++) {
echo $tdopen . $tdclose;
}
echo $trclose . "\n" .$endtable;
}
}
if ($reset == "Reset") {
$result = "";
$columns = "";
$rows = "";
$cellpadding = "";
$cellspacing = "";
$bordersize = "";
$width = "";
$bordercolor = "";
$bgcolor = "";
}
?>
<form method=post action=<?php print $PHP_SELF; ?>>
<table align="center"><tr><td>
<table cellspacing="5" border="0">
<tr align="left"><td>Number of Columns:</td><td><input type="text" size="8" name="columns" tabindex="1" value="<?php echo $columns ?>"></td>
<td>Number of Rows:</td><td><input type="text" size="8" name="rows" tabindex="2" value="<?php echo $rows ?>"><td></tr>
<tr align="left"><td>Cell Padding:</td><td><input type="text" size="8" name="cellpadding" tabindex="3" value="<?php echo $cellpadding ?>"></td>
<td>Cell Spacing:</td><td><input type="text" size="8" name="cellspacing" tabindex="4" value="<?php echo $cellspacing ?>"><td></tr>
<tr align="left"><td>Border Size:</td><td><input type="text" size="8" name="bordersize" tabindex="5" value="<?php echo $bordersize ?>"></td>
<td>Width (Pixels or %):</td><td><input type="text" size="8" name="width" tabindex="6" value="<?php echo $width ?>"></td></tr>
<tr align="left"><td>Border Color:</td><td><input type="text" size="8" maxlength="7" name="bordercolor" tabindex="7" value="<?php echo $bordercolor ?>"></td>
<td>Background Color:</td><td><input type="text" size="8" maxlength="7" name="bgcolor" tabindex="8" value="<?php echo $bgcolor ?>"></td></tr>
<tr align="left"><td><input type="submit" value="Generate!" name="submit" tabindex="9"></tr></td></table>
<textarea cols="50" rows="8" name="result" tabindex="10">
<?php echo $result; ?>
</textarea><BR>
<input type="submit" value="Preview" name="preview" tabindex="11">
<input type="submit" value="Reset" name="reset" tabindex="12"></td></tr></table>
</form>
the troubles in:
if ($submit == "Generate!") {
$result = $tableopen . "\n" .
$i = 0;
for ($i = $rows; $i > 0; $i++) {
echo $tropen;
for ($i = $columns; $i > 0; $i++) {
echo $tdopen . $tdclose;
}
echo $trclose . "\n" .$endtable;
}
}
it makes sense in my mind, knowing what i know about php. but im sure its completly wrong. its suppose to show table rows and columns according to the numbers imputted by the user.
im stuck, if someone could possible help it would be nice.
and one more question, on the generators ive used online, the page dosnt refresh when the generate code button is clicked, for mine it does, is it my code? or is it just because its in php? thanks
its a basic table gen, im a novice coder, im doing my best, i tried this far without seeking any help but im out of ideas. heres my code:
<?php
$table = "<table";
$tableclose = ">";
$tdopen = "<td>";
$tdclose = "</td>";
$tropen = "<tr>";
$trclose = "</tr>";
$endtable = "</table>";
if ($cellpadding != "") {
$padding = " " . "cellpadding" . "=" . "\"" . $cellpadding . "\"";
}
else {
$padding = "";
}
if ($cellspacing != "") {
$spacing = " " . "cellspacing" . "=" . "\"" . $cellspacing . "\"";
}
else {
$spacing = "";
}
if ($bordersize != "") {
$border = " " . "border" . "=" . "\"" . $bordersize . "\"";
}
else {
$border = "";
}
if ($width != "") {
$tablewidth = " " . "width" . "=" . "\"" . $width . "\"";
}
else {
$tablewidth = "";
}
if ($bordercolor != "") {
$borderc = " " . "bordercolor" . "=" . "\"" . $bordercolor . "\"";
}
else {
$borderc = "";
}
if ($bgcolor != "") {
$backgroundc = " " . "bgcolor" . "=" . "\"" . $bgcolor . "\"";
}
else {
$backgroundc = "";
}
$tableopen= $table . $padding . $spacing . $border . $tablewidth . $borderc . $backgroundc . $tableclose;
if ($submit == "Generate!") {
$result = $tableopen . "\n" .
$i = 0;
for ($i = $rows; $i > 0; $i++) {
echo $tropen;
for ($i = $columns; $i > 0; $i++) {
echo $tdopen . $tdclose;
}
echo $trclose . "\n" .$endtable;
}
}
if ($reset == "Reset") {
$result = "";
$columns = "";
$rows = "";
$cellpadding = "";
$cellspacing = "";
$bordersize = "";
$width = "";
$bordercolor = "";
$bgcolor = "";
}
?>
<form method=post action=<?php print $PHP_SELF; ?>>
<table align="center"><tr><td>
<table cellspacing="5" border="0">
<tr align="left"><td>Number of Columns:</td><td><input type="text" size="8" name="columns" tabindex="1" value="<?php echo $columns ?>"></td>
<td>Number of Rows:</td><td><input type="text" size="8" name="rows" tabindex="2" value="<?php echo $rows ?>"><td></tr>
<tr align="left"><td>Cell Padding:</td><td><input type="text" size="8" name="cellpadding" tabindex="3" value="<?php echo $cellpadding ?>"></td>
<td>Cell Spacing:</td><td><input type="text" size="8" name="cellspacing" tabindex="4" value="<?php echo $cellspacing ?>"><td></tr>
<tr align="left"><td>Border Size:</td><td><input type="text" size="8" name="bordersize" tabindex="5" value="<?php echo $bordersize ?>"></td>
<td>Width (Pixels or %):</td><td><input type="text" size="8" name="width" tabindex="6" value="<?php echo $width ?>"></td></tr>
<tr align="left"><td>Border Color:</td><td><input type="text" size="8" maxlength="7" name="bordercolor" tabindex="7" value="<?php echo $bordercolor ?>"></td>
<td>Background Color:</td><td><input type="text" size="8" maxlength="7" name="bgcolor" tabindex="8" value="<?php echo $bgcolor ?>"></td></tr>
<tr align="left"><td><input type="submit" value="Generate!" name="submit" tabindex="9"></tr></td></table>
<textarea cols="50" rows="8" name="result" tabindex="10">
<?php echo $result; ?>
</textarea><BR>
<input type="submit" value="Preview" name="preview" tabindex="11">
<input type="submit" value="Reset" name="reset" tabindex="12"></td></tr></table>
</form>
the troubles in:
if ($submit == "Generate!") {
$result = $tableopen . "\n" .
$i = 0;
for ($i = $rows; $i > 0; $i++) {
echo $tropen;
for ($i = $columns; $i > 0; $i++) {
echo $tdopen . $tdclose;
}
echo $trclose . "\n" .$endtable;
}
}
it makes sense in my mind, knowing what i know about php. but im sure its completly wrong. its suppose to show table rows and columns according to the numbers imputted by the user.
im stuck, if someone could possible help it would be nice.
and one more question, on the generators ive used online, the page dosnt refresh when the generate code button is clicked, for mine it does, is it my code? or is it just because its in php? thanks