469,601 Members | 2,039 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,601 developers. It's quick & easy.

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.php 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("$tableDat[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($tableAttrs);
$table->setAutoGrow(true);
$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->setHeaderContents($nr+1, 0, (string)$nr);
for ($i = 0; $i < 11; $i++) {
if ('' != $data[$nr][$i]) {
$table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
}
}
}
$table->altRowAttributes(1, null, $altRow);
?>
<?php
// This is where the titles for the cells on the header row are being defined.
$table->setHeaderContents(0, 0, '');
$table->setHeaderContents(0, 1, 'Recipient Name');
$table->setHeaderContents(0, 2, 'Recipient Address');
$table->setHeaderContents(0, 3, 'Docket #');
$table->setHeaderContents(0, 4, 'Version #');
$table->setHeaderContents(0, 5, 'Shipment #');
$table->setHeaderContents(0, 6, 'Job Name');
$table->setHeaderContents(0, 7, 'Job #');
$table->setHeaderContents(0, 8, 'Envelopes');
$table->setHeaderContents(0, 9, 'Cartons');
$table->setHeaderContents(0, 10, 'Pouches');
$table->setHeaderContents(0, 11, 'Skids');
$hrAttrs = array('bgcolor' => 'silver');
$table->setRowAttributes(0, $hrAttrs, true); // Here I am lost again, why is this true
$table->setColAttributes(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">Recipient name:<br>
<input type="text" name="recip"><br>
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>Carton:<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>
Mar 31 '07 #1
7 1674
ronverdonk
4,258 Expert 4TB
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
Mar 31 '07 #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
Thank you for the info, I read the guidelines, once, but got so flustered, it slipped my mind, my apoligies.
Apr 2 '07 #3
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("$tableDat[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->setHeaderContents($nr+1, 0, (string)$nr);
for ($i = 0; $i < 11; $i++) {
if ('' != $data[$nr][$i]) {
$table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
}
}
}
$table->altRowAttributes(1, null, $altRow);


$table->setHeaderContents(0, 0, '');
$table->setHeaderContents(0, 1, 'Recipient Name');
$table->setHeaderContents(0, 2, 'Recipient Address');
$table->setHeaderContents(0, 3, 'Docket #');
$table->setHeaderContents(0, 4, 'Version #');
$table->setHeaderContents(0, 5, 'Shipment #');
$table->setHeaderContents(0, 6, 'Job Name');
$table->setHeaderContents(0, 7, 'Job #');
$table->setHeaderContents(0, 8, 'Envelopes');
$table->setHeaderContents(0, 9, 'Cartons');
$table->setHeaderContents(0, 10, 'Pouches');
$table->setHeaderContents(0, 11, 'Skids');
$hrAttrs = array('bgcolor' => 'silver');
$table->setRowAttributes(0, $hrAttrs, true);
$table->setColAttributes(0, $hrAttrs);
[/PHP]
[HTML]
<form action="index4.php" method="post">
<table border="0">
<tr><td valign="top">Recipient name:<br>
<input type="text" name="recip"><br>
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>Carton:<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]
Apr 2 '07 #4
ronverdonk
4,258 Expert 4TB
I am not familiar with the package you are using, but can I assume that this statement
Expand|Select|Wrap|Line Numbers
  1. $table->setCellContents($nr+1, $i+1, $data[$nr][$i]);
is used to fill the rows of the table?

Ronald :cool:
Apr 2 '07 #5
I am not familiar with the package you are using, but can I assume that this statement
Expand|Select|Wrap|Line Numbers
  1. $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...
Apr 3 '07 #6
code green
1,726 Expert 1GB
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($tableAttrs);[/PHP]and start again, because as ronverdonk said we have no idea about the class package you are using
Apr 3 '07 #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($tableAttrs);[/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.
Apr 3 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Antoni | last post: by
1 post views Thread by Robbie | last post: by
2 posts views Thread by Tom | last post: by
5 posts views Thread by macluvitch | last post: by
27 posts views Thread by Erik de Castro Lopo | last post: by
1 post views Thread by Julien Sobrier | last post: by
5 posts views Thread by John Doe | last post: by
9 posts views Thread by subramanian100in | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.