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 8 of 8
  1. #1
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts

    making a php table gen

    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 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:

    PHP Code:
    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

  • #2
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    Where does $submit come from?

    Did you mean to say if($_POST['submit'])..

    HTH
    Dan
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #3
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    submits the name of the Generate button,

    in otherwords

    if ( Generate is Clicked ) {
    do
    }

    or maybe thats the wrong way to do it, but its been working so ive kept it. b/c i dont know how to do an onclick without javascript.

  • #4
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Does your reset button actually work too!?! Doesn't seem as if either should work. Unless you're using an extremely old version of PHP where you don't have to explicitly name your variables they just take on the name of your form elements. (Even still your Reset button shouldn't work.)



    @Whizard
    Thanks for helping me get my good name back :thumbs:
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #5
    Regular Coder Rappa's Avatar
    Join Date
    Nov 2005
    Location
    LI
    Posts
    356
    Thanks
    21
    Thanked 9 Times in 9 Posts
    lol no reset button works fine aswell, but if you dont mind me asking, how would you do it? or the correct way rather.

  • #6
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Well you are naming it "reset" but its actually a submit button. Instead of declaring the type as "submit" declare it to be "reset".
    Lets indent your code so thats its easier to point out.
    PHP Code:
    <form method=post action=<?php print $PHP_SELF?>>  //<---you have an extra greater than sign.
      <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">  //should set type to be "reset" not submit
          </td>
        </tr>
      </table>
    </form>
    I never did like mixing forms with tables...to much hassle.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Quote Originally Posted by StupidRalph View Post
    Does your reset button actually work too!?! Doesn't seem as if either should work. Unless you're using an extremely old version of PHP where you don't have to explicitly name your variables they just take on the name of your form elements. (Even still your Reset button shouldn't work.)
    That would work with register globals on(which is a bad idea), regardless of version.
    http://www.php.net/manual/en/security.globals.php

    You are correct about the reset button though, it would submit the form as well(should be <input type="reset").

    Also Rappa, the for loops should look like this:
    PHP Code:
    for ($i 0$i $rows$i++) 
    and
    PHP Code:
    for ($i 0$i $columns$i++) 
    Last edited by Inigoesdr; 08-12-2007 at 03:02 AM.

  • #8
    Senior Coder
    Join Date
    Mar 2003
    Location
    Atlanta
    Posts
    1,037
    Thanks
    14
    Thanked 30 Times in 28 Posts
    Quote Originally Posted by Inigoesdr View Post
    That would work with register globals on(which is a bad idea), regardless of version.
    http://www.php.net/manual/en/security.globals.php
    Oh okay, good catch. Register globals were on by default in the older versions I gotcha. Thats around the time I started fumbling with PHP, Register Globals was off by default, but most of the tutorials didn't reflect that yet. Good way to confuse someone who was new.
    Most of my questions/posts are fairly straightforward and simple. I post long verbose messages in an attempt to be thorough.


  •  

    Posting Permissions

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