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