Then I loop through my data and fill in the table cells.
The row data from the query is transposed so rows become columns in the array.
For some reason when I have less than a full page worth of data, some of the blank cells (not all) in the columns with no data in the array are deleted. In the table columns with no data rows below 5 are deleted. (see sample photo of results)
If I comment out the section where the data is loaded into the array then every column has missing cells.
My thought was I was reading the coordinates wrong, but that does not make sense as the data that is displayed are in the correct cells when I have a full page.
Am I reading the array incorrectly or what else could be deleting the array elements.
Here is my code, I have bolded what I think is the relevant text.
Expand|Select|Wrap|Line Numbers
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
- <?php
- try
- {
- ...some query code...
- if ( $result = $db->query($sql) )
- {
- if ( $result->num_rows > 0)
- {
- ?>
- <html>
- <head>
- <title>Printable Soil Boring Samples</title>
- </head>
- <body>
- <form>
- <?php
- $cPageCnt = 1;
- $cRecCnt = 0;
- $cBoring = '';
- while ($row = $result->fetch_array())
- {
- $cRecCnt ++;
- if (!isset($pObj)){
- //set boring flag
- $cBoring = $row["boring"];
- //create page object if not exists
- $pObj = new pageObject($row, $cPageCnt);
- $pObj->loadRow($row, $cRecCnt);
- }else if($cBoring != $row["boring"] or $cRecCnt > 10){
- //print page object if new boring or record count has exceeded page
- $pObj->printPage();
- //insert page break
- echo '<span class="newPage"></span>';
- //re-initilize control variables
- //reset record counter
- $cRecCnt = 1;
- //reset boring flag
- $cBoring = $row["boring"];
- //destroy page object
- unset($pObj);
- //advace page count
- $cPageCnt ++;
- //create new page object
- $pObj = new pageObject($row, $cPageCnt);
- $pObj->loadRow($row, $cRecCnt);
- }else{
- //add row data to page object
- $pObj->loadRow($row, $cRecCnt);
- }
- }
- if (isset($pObj)){
- //some data is left to print
- $pObj->printPage();
- //destroy page object
- unset($pObj);
- }
- ?>
- </form>
- </body>
- </html>
- <?php
- }
- }
- }
- catch (exception $e)
- {
- echo 'An error occured : ' .$e->getMessage();
- }
- class pageObject
- {
- //properties
- public $jobId;
- public $boring;
- public $date;
- public $page;
- public $project;
- public $client;
- public $engineer;
- public $webUser;
- //detail sample infor for boring
- public $colArray;
- //methods
- public function __construct( $row, $cPageCnt ) {
- //page header info for specific boring
- $this->jobId = $row["jobid"];
- $this->boring = $row["boring"];
- $this->date = $row["sampleDate"];
- $this->page = $cPageCnt;
- $this->project = $row['prjctname'];
- $this->client = $row['name'];
- $this->engineer = $row['engineer'];
- $this->webUser = trim($row['webUser']);
- //detail sample infor for boring
- $this->colArray = array_fill(0, 11, array_fill(0, 22, " "));
- /*
- -------------------
- fill in row headers
- -------------------
- */
- $this->colArray[0][0] = "Boring";
- $this->colArray[1][0] = "Sample #";
- $this->colArray[2][0] = "Depth in Feet";
- $this->colArray[3][0] = "No. of Blows";
- $this->colArray[4][0] = "Type";
- $this->colArray[5][0] = "Container Number";
- $this->colArray[6][0] = "Wet weight of<br/>Sample + Container";
- $this->colArray[7][0] = "Dry weight of<br/>Sample + Container";
- $this->colArray[8][0] = "Weight of container";"Percent moisture";
- $this->colArray[9][0] = "Percent moisture";
- $this->colArray[10][0] = "Weight of sample in air";
- $this->colArray[11][0] = "Weight of sample in water";
- $this->colArray[12][0] = "Weight of water";
- $this->colArray[13][0] = "Disp. Dry unit weight in<br/>pounds per cubic foot";
- $this->colArray[14][0] = "Dim. Dry unit weight in<br/>pounds per cubic foot";
- $this->colArray[15][0] = "Dry unit scale weight";
- $this->colArray[16][0] = "Dimension<br/>(Diameter * Length)";
- $this->colArray[17][0] = "Qu (TSF)";
- $this->colArray[18][0] = "Qu % failure";
- $this->colArray[19][0] = "Qp (TSF)";
- $this->colArray[20][0] = "Tv";
- $this->colArray[21][0] = "Soil description";
- }
- public function loadRow($row, $cRecCnt){
- /*
- --------------------------------
- fill in columns with sample data
- --------------------------------
- */
- $this->colArray[0][$cRecCnt] = ( empty($row["boring"] )) ?" " :$row["boring"];
- $this->colArray[1][$cRecCnt] = ( empty($row["sample"] )) ?" " :$row["sample"];
- $this->colArray[2][$cRecCnt] = ( empty($row["depth"] )) ?" " :$row["depth"];
- $this->colArray[3][$cRecCnt] = ( empty($row["blows"] )) ?" " :$row["blows"];
- $this->colArray[4][$cRecCnt] = ( empty($row["sampleType"] )) ?" " :$row["sampleType"];
- $this->colArray[5][$cRecCnt] = ( empty($row["contNumb"] )) ?" " :$row["contNumb"];
- $this->colArray[6][$cRecCnt] = ( $row['WWofSC'] == 0) ?" " :$row['WWofSC'];
- $this->colArray[7][$cRecCnt] = ( $row['DWofSC'] == 0) ?" " :$row['DWofSC'];
- $this->colArray[8][$cRecCnt] = ( $row['contWeight'] == 0) ?" " :$row['contWeight'];
- $this->colArray[9][$cRecCnt] = ( $row['moisture'] == 0) ?" " :$row['moisture'];
- $this->colArray[10][$cRecCnt] = ( $row['sampleInAir'] == 0) ?" " :$row['sampleInAir'];
- $this->colArray[11][$cRecCnt] = ( $row['sampleInWater'] == 0) ?" " :$row['sampleInWater'];
- $this->colArray[12][$cRecCnt] = ( $row['water'] == 0) ?" " :$row['water'];
- $this->colArray[13][$cRecCnt] = ( $row['dryUnit'] == 0) ?" " :$row['dryUnit'];
- $this->colArray[14][$cRecCnt] = ( $row['dimDryUnit'] == 0) ?" " :number_format($row['dimDryUnit'], 1, '.', '');
- $this->colArray[15][$cRecCnt] = ( $row['dimWeight'] == 0) ?" " :number_format($row['dimWeight'], 1, '.', '');
- $this->colArray[16][$cRecCnt] = ( $row["dimDiameter"] == 0) ?" " :$row["dimDiameter"];
- $this->colArray[17][$cRecCnt] = ( empty($row["qu"] )) ?" " :$row["qu"];
- $this->colArray[18][$cRecCnt] = ( empty($row["percentFail"] )) ?" " :$row["percentFail"];
- $this->colArray[19][$cRecCnt] = ( empty($row["qp"] )) ?" " :$row["qp"];
- $this->colArray[20][$cRecCnt] = ( empty($row["tv"] )) ?" " :$row["tv"];
- $this->colArray[21][$cRecCnt] = ( empty($row["soilDesc"] )) ?" " :$row["soilDesc"];
- }
- public function printPage(){
- ?>
- <table
- bgcolor="#FFFFFF"
- width="100%"
- >
- <tr>
- <td colspan="2">Job #:<?php echo $this->jobId ?></td>
- </tr>
- </table>
- <table border="1">
- <?php
- for ($i=0; $i <= 21; $i++) {
- echo '<tr>';
- echo '<td>'.$this->colArray[$i][0].'</td>';
- echo '<td>'.$this->colArray[$i][1].'</td>';
- echo '<td>'.$this->colArray[$i][2].'</td>';
- echo '<td>'.$this->colArray[$i][3].'</td>';
- echo '<td>'.$this->colArray[$i][4].'</td>';
- echo '<td>'.$this->colArray[$i][5].'</td>';
- //fails below here when there is no data in column
- echo '<td>'.$this->colArray[$i][6].'</td>';
- echo '<td>'.$this->colArray[$i][7].'</td>';
- echo '<td>'.$this->colArray[$i][8].'</td>';
- echo '<td>'.$this->colArray[$i][9].'</td>';
- echo '<td>'.$this->colArray[$i][10].'</td>';
- echo '</tr>';
- }
- echo '</table>';
- }
- }
- ?>