PHP Table Issue


#1

I am not sure if its my code or the amount of jobs i have open but. Can anyone spot why my list of jobs appears lower than the other engineers from the image example i want all jobs to appear like “Martins” but other engineers jobs appear differently not a top like i expected.

Below is my HTML & PHP code + my CSS

[php]

<?php include('connectionDB.php'); $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='James'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

James

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php include('connectionDB.php'); $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Martin'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Martin

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php include('connectionDB.php'); $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Other'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Other

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php include('connectionDB.php'); $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Nik'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Nik

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Matthew'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Matthew

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Paul'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Paul

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php $sql = "SELECT * FROM [Support_DB].[dbo].['Job info$'] WHERE [Job Completed?]= 0 AND [Attended by]='Matt'"; $stmt = $conn->prepare($sql); $stmt->execute(); $results=$stmt->fetchAll(PDO::FETCH_ASSOC); ?>

Matt

<?php foreach ($results as $row) { echo "
"; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo""; echo"
"; echo $row['Customer']; echo""; echo $row['Job Number']; echo"
"; echo wordwrap($row['Fault'],85,"
\n",TRUE); echo"
"; echo"
"; } ?>
<?php

$sql = “SELECT * FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0 AND [Attended by]=‘Emma’”;
$stmt = $conn->prepare($sql);
$stmt->execute();
$results=$stmt->fetchAll(PDO::FETCH_ASSOC);
?>







Emma




<?php foreach ($results as $row) {
echo “
”;
echo"";
echo"";
echo"";
echo"";
echo"";
echo"";
echo"";
echo"";
echo"";
echo"
";
echo $row[‘Customer’];
echo"
";
echo $row[‘Job Number’];
echo"
";
echo wordwrap($row[‘Fault’],85,"
\n",TRUE);
echo"
";
echo"
";
}
?>
[/php]

The CSS is the following:
[php]
background, body{
background-color: black;
}

#table-eng, p{
width: 650%;
font-size: 15pt;
color: #ffffff;
border-bottom-style: none;
}

#table-cust, tr{
font-size: 13pt;
color: #ffffff;
}

.td-fault{
font-size: 11pt;
color: #4CBB17;
border-bottom: 1px solid white;
}

[/php]

If anyone could offer any suggestions or assistance that would be great.

Thanks James


Jobs.JPG


#2

Where to begin?

  1. Repeating code for each value isn’t good programming. Don’t Repeat Yourself (DRY.) The repeated region of html should exist only once and you re-use it with different input data. You only need about 60 lines of code to accomplish this. By repeating the code for each value, when you do find the problem, you will have to make the correction in multiple places. You also need to separate the database specific code (that knows how to query for and retrieve the data) from the presentation code (that knows how to produce the output from the data.) This will let you dump/display the data to make sure it is what you expect.

You should have one query that gets the data you want in the order that you want it, then fetch this data into an appropriately named php variable. This logic should come before the start of your html document. This variable is then the input to the presentation logic, that is located inside the html document.

  1. We don’t know what exact output you do expect, so, telling us some portion of the output should be like some other portion, doesn’t help us to help you. Are you even trying to display the data in two columns or just one column and you do realize that with variable amounts of data that a two column layout will leave uneven amounts of blank space? What rule determines the order of the Attended by values?

  2. You should always validate the resultant html at validator.w3.org. At a minimum, you have extra tag(s) that are breaking the html markup.


#3

Hi Phdr,

The PHP repat of the code querys the jobinfo table and pulls back the SQL data dependent on the name of the enginner.

I would like the data to displayed in 4 rows with 2 colums with the engineers name at the top each coloum and the jobs for that engineer under there name. (see attachment)

After posting i noticed the extra

tags and removed them with no change in the rendered version also removed the mutiple includes.

job-board.JPG


#4

You need to validate the output, per item #3 in my post. There are still several problems in the html markup, some of which may be causing the unexpected output. You even have a 650% width in the css, which is invalid.

After looking more closely at the massive amount of code to try to figure out what it is actually doing, I can tell you why the different amounts of output under each engineer doesn’t align at the top. The main table cell the output is in will be the height of the largest amount of output and because you are building the output as tables inside of tables, the smaller content is floating and being centered in the available space. I recommend that you simplify what you are doing and use just ONE table to produce this tabular output. The engineer names in the four columns in each row will be within the same table row and will align.

To simplify all the code/queries, per item #1 in my post, so that you only have one instance of any particular markup, making it easier to make fixes and changes, see the following -

[php]<?php
require ‘connectionDB.php’;

$columns = 4; // number of columns per row

// use one query that gets the data you want in the order that you want it - modify query with a sort order if known
$sql = “SELECT * FROM [Support_DB].[dbo].[‘Job info$’] WHERE [Job Completed?]= 0”;
$stmt = $conn->query($sql); // nothing to prepare, just execute the query
$results = [];
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
// pivot/index data by the ‘Attended by’ value
$results[$row[‘Attended by’]][] = $row;
}

// break the data into table rows, 4 columns per row
$results = array_chunk($results, $columns, true);
?>

A bunch of tables for a layout
<?php foreach($results as $arr) { ?> <?php foreach($arr as $attended=>$data) { ?> <?php } ?> <?php } ?>

<?php echo $attended; ?>

<?php foreach($data as $row) { ?>
<?php echo $row['Customer']; ?> <?php echo $row['Job Number']; ?>
<?php echo wordwrap($row['Fault'],85,"
\n",TRUE); ?>
<?php } ?>
[/php]

#5

Thank you Phdr,

I have learnt something there, but the table is still as before once rendered rather than them all been equal.

The output under each engineer should align at the top.

Also is there any way i can remove not show a certain ‘attended by’ engineer “quoted”

Thanks James