Article 4WXHY code displays many blank lines before showing table

code displays many blank lines before showing table

by
pizzipie
from LinuxQuestions.org on (#4WXHY)
I need another pair of eyes to spot what I have done to start my program and have it show almost a blank screen . You have to scroll down a page or so to see the table that was produced by php.

Opened database successfullyshows in upper left of screen then you have to scroll down to see the table.
Here is code:

Code:<?php
error_reporting (E_ALL ^ E_NOTICE);
include("myPhpFunctions.inc"); // contains lf(); sp(); myprint; check_input();

$headarr=$rows=$arr=array();
$str=$str1="";

// ======================================================================
// Connect to Database and SELECT query
// =====================================================================

class MyDB extends SQLite3 {
function __construct() {
$this->open('linuxQuest.db'); // short version for testing
//$this->open('/home/rick/Desktop/sqliteDatabases/renoAZID.db');
}
}
$db = new MyDB();
if(!$db) {
echo $db->lastErrorMsg();
} else {
echo "Opened database successfully\n";
}

$sql =<<<EOF
SELECT * from query; // query is a view Table in the database
EOF;

$ret = $db->query($sql);
while($row = $ret->fetchArray(SQLITE3_ASSOC) ) { // runs SELECTION query on Table rdata
$rows[]=$row; // array of all $row arrays
} // while

// ======================================================================
// Manipulate SELECT query as per comments
// =====================================================================

$x=array_shift($rows); // take grand total array off front of array $rows
array_push($rows,$x); // put it on end of array $rows
for($i=0; $i<count($rows); $i++) {
array_walk($rows[$i], "process");
}

$r=count($rows)-1;
$gtotal='<b>$ '.$rows[$r]['Amount'].'</b>';
$rows[$r]['Amount']=$gtotal; // change Grand Total format to include bold and $ in front of Amount

foreach($rows as $key => $arr) {
$subTFlag=0;
foreach($arr as $key2 => $value) {
if($key2=='Category') {
$str= trim($value, '<b></b>'); // find Sub Total lines
$str1=substr($str,-9); lf();
if($str1=="Sub Total") {
$subTFlag=1;
}
}
} // foreach $arr

if($subTFlag) {
$value='<b>$ '.$value.'</b>'; // format $value to bold $ $value
$rows[$key]['Amount']=$value;
$subTFlag==0;
}
} // foreach $rows

$headarr=array_keys($rows[0]); // get the $keys for use as table column headers
?>

<!--======================================================================
Set Up Table for display
=====================================================================-->

<!DOCTYPE html>

<html>

<head>
<title>Wed 20 Dec 2019 Renovation Data</title>
<link rel="stylesheet " type="text/css" href="renoAZID.css" />
</head>
<body>

<?php

echo "<h2>Renovation Cost Data</h2>";

echo "<table id='t02' align='center'>"; // create table

foreach($headarr as $str) { // create header columns
echo '<th>'.$str.'</th>'.lf();
}
echo '<tr></tr>';
foreach($rows as $index => $arr) { // fill table with data
echo '<tr>';
foreach($arr as $key => $value) {
echo '<td>'.$value.'</td>';
}
echo '</tr>';
}
echo '</table>';
?>

<!--======================================================================
close down Database and exit
=====================================================================-->

</body>
</html>

<?php

lf();lf();
$db->close();
echo lf()."Closed database successfully";

// ======================================================================
// Function Declarations
//
// 1. string process(&$value, $key2)
// $value is passed by reference so it can be changed in database
// =====================================================================

function process(&$value, $key2) { // used in Arrary_walk to manipulate (change) data and format of data

// for use in array_walk to change column values

if($key2=='Category' && strtolower(substr($value, -3))=="sub") {
$value='<b>'.ucfirst(substr($value, 0, strlen($value)-3)).'&nbsp'.'Sub Total</b>';
}
elseif($key2=='Category' && strtolower(trim($value))=='grand') {
$value='<b>Renovation Grand Total</b>';
}
elseif($key2=='Amount') {
$value=number_format($value,2);
}

} // process

// END OF PROGRAM
?>latest?d=yIl2AUoC8zA latest?i=ptE0lPRf-tk:WaD21TSDh7A:F7zBnMy latest?i=ptE0lPRf-tk:WaD21TSDh7A:V_sGLiP latest?d=qj6IDK7rITs latest?i=ptE0lPRf-tk:WaD21TSDh7A:gIN9vFwptE0lPRf-tk
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments