Trouble incrementing data with HTML_Table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jwhitby3
    New Member
    • Mar 2007
    • 7

    Trouble incrementing data with HTML_Table

    Hi all, I am trying to develop what amounts to a data entry page for the company I work for, (mostly to make my job easier). I think that I am beginning to grasp php, but I am at a loss now. I understand how to use HTML_Table to add a table to a page, and that portion of my project is coming along nicely. The problem is at this point, that I can't figure out how to increment the row that gets written to. Row 0 just keeps getting overwritten.
    There are a lot of things here that are probably gonna seem overkill to the guys who really know what they are doing, but I am trying to teach myself, how to do this. I've added comments to the source code, to try and relay what I understand things to mean. Please correct me if I'm wrong...I am totally new at this, a a week of solid study, and this is where I am so far. Almost all of this is copied from a lesson on HTML_Table, I have been trying to tear it down, and make it work, I mostly (I think anyway) understand what is being done, but I cannot figure out how to increment from row 0, to row 1, then 2 etc...
    Thank you in advance for any help and explanation, and for dealing with my probably inane questions.

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
    <title>index.ph p v.04</title>
    </head>
    <body>
    <?php
    // I read that variables should be defined or set before being initialized. This is what
    // I thought that they meant.
    $tableDat[] = "0"
    // This was the only way that I could get the different $_POST values assigned to the array
    // I'm sure there is a better way, but this worked, so I stuck with it.
    $tableDat[0] = $_POST['recip'];
    $tableDat[1] = $_POST['address'];
    $tableDat[2] = $_POST['docket'];
    $tableDat[3] = $_POST['version'];
    $tableDat[4] = $_POST['shipment'];
    $tableDat[5] = $_POST['jobname'];
    $tableDat[6] = $_POST['jobnum'];
    $tableDat[7] = $_POST['envel'];
    $tableDat[8] = $_POST['carton'];
    $tableDat[9] = $_POST['pouch'];
    $tableDat[10] = $_POST['skid'];
    ?>
    <?php
    // This section is being used for the basic layout of the table, created by HTML_table. I think
    // that in order for the data to be incremented, that I should make column 0 a variable
    // assigned higher up, something like $foobar = "0", and then write a small incrementer, so
    // that the row number will change 0, 1, 2, etc. I tried it, and I learned in short order, I have
    // very little notion of what in fact is going on here.
    $data = array(
    '0' => array("$tableDa t[0]", "$tableDat[1]", "$tableDat[2]", "$tableDat[3]", "$tableDat[4]", "$tableDat[5]", "$tableDat[6]", "$tableDat[7]", "$tableDat[8]", "$tableDat[9]", "$tableDat[10]"),
    '1' => array(""),
    '2' => array("")
    );
    ?>
    <?php
    // The class inclusion and setting the attributes of the table to be made. This I get, mostly
    // anyway.
    require_once 'HTML/Table.php';
    $tableAttrs = array('width' => '600'); // Why is this assigned to an array?
    $table = new HTML_Table($tab leAttrs);
    $table->setAutoGrow(tr ue);
    $table->setAutoFill( 'n/a');
    ?>
    <?php
    // This section, lost me completely. I can see that this is being used to increment something
    // I'm just lost on where some of this stuff is coming from, especially the $nr, is that a
    // special variable? As I sit here staring at this I think i get it. $nr = 0, which I am taking is
    // referring to column 0, and is incrementing it by one...ok if this is the increment step,
    // why isn't it working? What did I do wrong?
    for ($nr = 0; $nr < count($data); $nr++) {
    $table->setHeaderConte nts($nr+1, 0, (string)$nr);
    for ($i = 0; $i < 11; $i++) {
    if ('' != $data[$nr][$i]) {
    $table->setCellContent s($nr+1, $i+1, $data[$nr][$i]);
    }
    }
    }
    $table->altRowAttribut es(1, null, $altRow);
    ?>
    <?php
    // This is where the titles for the cells on the header row are being defined.
    $table->setHeaderConte nts(0, 0, '');
    $table->setHeaderConte nts(0, 1, 'Recipient Name');
    $table->setHeaderConte nts(0, 2, 'Recipient Address');
    $table->setHeaderConte nts(0, 3, 'Docket #');
    $table->setHeaderConte nts(0, 4, 'Version #');
    $table->setHeaderConte nts(0, 5, 'Shipment #');
    $table->setHeaderConte nts(0, 6, 'Job Name');
    $table->setHeaderConte nts(0, 7, 'Job #');
    $table->setHeaderConte nts(0, 8, 'Envelopes');
    $table->setHeaderConte nts(0, 9, 'Cartons');
    $table->setHeaderConte nts(0, 10, 'Pouches');
    $table->setHeaderConte nts(0, 11, 'Skids');
    $hrAttrs = array('bgcolor' => 'silver');
    $table->setRowAttribut es(0, $hrAttrs, true); // Here I am lost again, why is this true
    $table->setColAttribut es(0, $hrAttrs); // and this one just is...
    ?>
    <?php
    $table->display();
    ?>
    // This is the actual form itself. I have the action set to index4.php, so that the processed
    // info will be displayed on this page.
    <form action="index4. php" method="post">
    <table border="0">
    <tr><td valign="top">Re cipient name:<br>
    <input type="text" name="recip"><b r>
    Recipient Location:<br>
    <textarea name="address" rows="4" cols="30" >
    </textarea></td>
    <td valign="top" >
    Docket # <br>
    Version #<br>
    Shipment #<br>
    Job Name:<br>
    Job #<br>

    </td>
    <td valign="top">
    <input type="text" name="docket" size="10"><br>
    <input type="text" name="version" size="10"><br>
    <input type="text" name="shipment" size="10"><br>
    <input type="text" name="jobname" size="10"><br>
    <input type="text" name="jobnum" size="10"><br>
    </td>
    <td valign="top">
    Envelope:<br>Ca rton:<br>Pouch: <br>Skid:
    </td>
    <td valign="top">
    <input type="text" name="envel" size="10"><br>
    <input type="text" name="carton" size="10"><br>
    <input type="text" name="pouch" size="10"><br>
    <input type="text" name="skid" size="10"><br>
    </tr></table>
    <input type="submit" value="Add to logsheet">
    </form>
    </body>
    </html>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Welcome to TSDN.

    Before you continue posting in this forum, READ THE POSTING GUIDELINES!!

    Especially the part about enclosing shown code within code or php tags! You code is unreadable without an IDE.

    moderator

    Comment

    • jwhitby3
      New Member
      • Mar 2007
      • 7

      #3
      Originally posted by ronverdonk
      Welcome to TSDN.

      Before you continue posting in this forum, READ THE POSTING GUIDELINES!!

      Especially the part about enclosing shown code within code or php tags! You code is unreadable without an IDE.

      moderator
      Thank you for the info, I read the guidelines, once, but got so flustered, it slipped my mind, my apoligies.

      Comment

      • jwhitby3
        New Member
        • Mar 2007
        • 7

        #4
        I am trying to set up a minimal web page, that will allow me to use a form, to input my daily log info, and php to format, display, the log onscreen. I have been successful in making everything that I have so far work, the problem is, I have not been able to figure out where our how to write a counter, to increment, which row the data gets written to. Starting at 0, then 1, then 2 etc.
        Here is what I have so far.

        [PHP]
        $tableDat[] = "0"
        $tableDat[0] = $_POST['recip'];
        $tableDat[1] = $_POST['address'];
        $tableDat[2] = $_POST['docket'];
        $tableDat[3] = $_POST['version'];
        $tableDat[4] = $_POST['shipment'];
        $tableDat[5] = $_POST['jobname'];
        $tableDat[6] = $_POST['jobnum'];
        $tableDat[7] = $_POST['envel'];
        $tableDat[8] = $_POST['carton'];
        $tableDat[9] = $_POST['pouch'];
        $tableDat[10] = $_POST['skid'];

        $data = array(
        '0' => array("$tableDa t[0]", "$tableDat[1]", "$tableDat[2]", "$tableDat[3]", "$tableDat[4]", "$tableDat[5]", "$tableDat[6]", "$tableDat[7]", "$tableDat[8]", "$tableDat[9]", "$tableDat[10]"),
        '1' => array(""),
        '2' => array("")
        );

        for ($nr = 0; $nr < count($data); $nr++) {
        $table->setHeaderConte nts($nr+1, 0, (string)$nr);
        for ($i = 0; $i < 11; $i++) {
        if ('' != $data[$nr][$i]) {
        $table->setCellContent s($nr+1, $i+1, $data[$nr][$i]);
        }
        }
        }
        $table->altRowAttribut es(1, null, $altRow);


        $table->setHeaderConte nts(0, 0, '');
        $table->setHeaderConte nts(0, 1, 'Recipient Name');
        $table->setHeaderConte nts(0, 2, 'Recipient Address');
        $table->setHeaderConte nts(0, 3, 'Docket #');
        $table->setHeaderConte nts(0, 4, 'Version #');
        $table->setHeaderConte nts(0, 5, 'Shipment #');
        $table->setHeaderConte nts(0, 6, 'Job Name');
        $table->setHeaderConte nts(0, 7, 'Job #');
        $table->setHeaderConte nts(0, 8, 'Envelopes');
        $table->setHeaderConte nts(0, 9, 'Cartons');
        $table->setHeaderConte nts(0, 10, 'Pouches');
        $table->setHeaderConte nts(0, 11, 'Skids');
        $hrAttrs = array('bgcolor' => 'silver');
        $table->setRowAttribut es(0, $hrAttrs, true);
        $table->setColAttribut es(0, $hrAttrs);
        [/PHP]
        [HTML]
        <form action="index4. php" method="post">
        <table border="0">
        <tr><td valign="top">Re cipient name:<br>
        <input type="text" name="recip"><b r>
        Recipient Location:<br>
        <textarea name="address" rows="4" cols="30" >
        </textarea></td>
        <td valign="top" >
        Docket # <br>
        Version #<br>
        Shipment #<br>
        Job Name:<br>
        Job #<br>

        </td>
        <td valign="top">
        <input type="text" name="docket" size="10"><br>
        <input type="text" name="version" size="10"><br>
        <input type="text" name="shipment" size="10"><br>
        <input type="text" name="jobname" size="10"><br>
        <input type="text" name="jobnum" size="10"><br>
        </td>
        <td valign="top">
        Envelope:<br>Ca rton:<br>Pouch: <br>Skid:
        </td>
        <td valign="top">
        <input type="text" name="envel" size="10"><br>
        <input type="text" name="carton" size="10"><br>
        <input type="text" name="pouch" size="10"><br>
        <input type="text" name="skid" size="10"><br>
        </tr></table>
        <input type="submit" value="Add to logsheet">
        </form>
        </body>
        </html>
        [/HTML]

        Comment

        • ronverdonk
          Recognized Expert Specialist
          • Jul 2006
          • 4259

          #5
          I am not familiar with the package you are using, but can I assume that this statement
          Code:
          $table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
          is used to fill the rows of the table?

          Ronald :cool:

          Comment

          • jwhitby3
            New Member
            • Mar 2007
            • 7

            #6
            Originally posted by ronverdonk
            I am not familiar with the package you are using, but can I assume that this statement
            Code:
            $table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
            is used to fill the rows of the table?

            Ronald :cool:
            I believe so. I am quite new to PHP, but from what I have been able to put together, that is part of a counter function, to increment the row that data is being written too. However if that is in fact what it is, it's not working. No doubt because of my lack of understanding, as to how to implement it. Most of this I got examples I found on the net as to how to use HTML_Table. I'm just not grokking it.

            The main problem is that all the examples are designed around pulling the information out of a database, I'm trying to modify to accept input from a web form...

            Comment

            • code green
              Recognized Expert Top Contributor
              • Mar 2007
              • 1726

              #7
              You are trying to use a class when you obviously don't understand classes.
              Drop this class, go back to basics
              [PHP]$table = new HTML_Table($tab leAttrs);[/PHP]and start again, because as ronverdonk said we have no idea about the class package you are using

              Comment

              • jwhitby3
                New Member
                • Mar 2007
                • 7

                #8
                Originally posted by code green
                You are trying to use a class when you obviously don't understand classes.
                Drop this class, go back to basics
                [PHP]$table = new HTML_Table($tab leAttrs);[/PHP]and start again, because as ronverdonk said we have no idea about the class package you are using
                I thank you for taking a look at the code anyway. I appreciate you guys taking the time to do so. If and when I manage to get this figured out, I will try to come back and relay the information that I have gained.

                Comment

                Working...