Link to home
Start Free TrialLog in
Avatar of DS928
DS928Flag for United States of America

asked on

Formatting PHP Table

I am trying to format a table.  Everything is bunched up.  I need some separation as well as the lines showing for the table.  This is what I have so far.

$sql = "SELECT recordId, recordCust, recordSite, recordUser, recordPass, recordDateAdded FROM records";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "Record" . $row["recordId"]. "Customer" . $row["recordCust"]. "Site " . $row["recordSite"]. "User" . $row["recordUser"]. "Password" . $row["recordPass"]. "Date" . $row["recordDateAdded"]."<br>";
    }
} else {
    echo "0 results";
}

Open in new window

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

I don't see any markup other than the br tag at the end of the line, and with no id or classname I have to assume that you also do not have any CSS applied.  So if you want to for mat it as a table do the tagging for a table and put the styling you need in a stylesheet.

Cd&
Avatar of DS928

ASKER

Ok, agreed.  How do I apply a style sheet to this?
CSS works by using "selectors" to apply styling to HTML elements.  You use HTML to provide semantic markup, attaching meaning to the data elements on the page.  You use CSS to affect the appearance of the data elements.  Learning CSS can take some time, but there are many good online and published resources.  Make a Google search for "Learn CSS" and you will find many good examples.  And from personal experience, I can recommend this book.
http://www.amazon.com/Book-CSS3-Developers-Future-Design/dp/1593275803/

Here's an example.  See lines 8-18.
http://iconoun.com/demo/ds928.php

<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<style type="text/css">
body {
    background-color:yellow;
}
#vibrant {
    color:red;
}
.stuff {
    padding-left:4em;
}
</style>

<title>HTML5 Page With CSS</title>
</head>
<body>

<h2 id="vibrant">Here are some data fields styled with CSS <i>padding</i></h2>
<span class="stuff">Field 1</span>
<span class="stuff">Field 2</span>
<span class="stuff">Field 3</span>

</body>
</html>

Open in new window

Avatar of DS928

ASKER

I have this but it did not work.
<style type=”text/css”>
table {
margin: 8px;
}

th {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
background: #666;
color: #FFF;
padding: 2px 6px;
border-collapse: separate;
border: 1px solid #000;
}

td {
font-family: Arial, Helvetica, sans-serif;
font-size: .7em;
border: 1px solid #DDD;
}
</style>

Open in new window


$sql = "SELECT recordId, recordCust, recordSite, recordUser, recordPass, recordDateAdded FROM records";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "<table>";
		echo "Record" . $row["recordId"]. "Customer" . $row["recordCust"]. "Site" . $row["recordSite"]. "User" . $row["recordUser"]. "Password" . $row["recordPass"]. "Date" . $row["recordDateAdded"]."<br>";
    }
} else {
    echo "0 results";
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial