Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Generator Help

  1. #1
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts

    Generator Help

    Hello all. I'm attempting to make a Table Generator in PHP. So far so good, although i'm a very novice coder, I can manage to get by with what I know with probably more difficult ways than i have to. Anyway heres my problem:

    So you have all the feilds where you input data right, then you have the submit button, and the text area where the code is shown. Well once the values are inputted, and the button is clicked, the code is shown, however, all the feilds above just go blank. I want the values in the feilds to stay in the form until the user clicks the reset button.

    Heres what I have so far: Id appreciate it if no one made fun of my code, i'm just starting to learn PHP, and besides this isnt done yet.

    PHP Code:
    <?php
    $table 
    "<table";
    $tableclose ">";

    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;
    }

    if (
    $reset == "Reset") {
    $result "";
    }
    ?>
    <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="5" name="columns"></td></tr>
    <tr align="left"><td>Number of Rows:</td><td><input type="text" size="5" name="rows"><td></tr>
    <tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding"><td></tr>
    <tr align="left"><td>Cell Spacing:</td><td><input type="text" size="5" name="cellspacing"><td></tr>
    <tr align="left"><td>Border Size:</td><td><input type="text" size="5" name="bordersize"></td></tr>
    <tr align="left"><td>Width (Pixels or %):</td><td><input type="text" size="5" name="width"></td></tr>
    <tr align="left"><td>Border Color:</td><td><input type="text" size="10" name="bordercolor"></td></tr>
    <tr align="left"><td>Background Color:</td><td><input type="text" size="10" name="bgcolor"></td></tr>
    <tr align="left"><td><input type="submit" value="Generate!" name="submit"></tr></td></table>
    <textarea cols="50" rows="8" name="result">
    <?php echo $result?>
    </textarea><BR>
    <input type="submit" value="Preview" name="preview">
    <input type="submit" value="Reset" name="reset"></td></tr></table>
    </form>
    but any suggestions on how to make my life easier while learning PHP would be nice too.

    -Anthony

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    As an example:
    Change this:
    Code:
    <tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding"><td></tr>
    to:
    PHP Code:
    <tr align="left"><td>Cell Padding:</td><td><input type="text" size="5" name="cellpadding" value="<?php echo $cellpadding ?>"><td></tr>

  • #3
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    ahh alright cool, thanks for that. Now im not quite sure on how to go about generating the rows and cells. Any suggestions?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •