Solved

Formatting PHP Table

Posted on 2015-01-24
5
76 Views
Last Modified: 2015-01-25
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

0
Comment
Question by:DS928
  • 2
  • 2
5 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 40568405
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&
0
 

Author Comment

by:DS928
ID: 40568433
Ok, agreed.  How do I apply a style sheet to this?
0
 
LVL 109

Expert Comment

by:Ray Paseur
ID: 40568531
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

0
 

Author Comment

by:DS928
ID: 40568857
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

0
 
LVL 109

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40569232
Probably what you want to do is deconstruct this problem into the SSCCE parts.  If your query is working correctly (ie: It is returning the expected results set) then your issues would probably be in the HTML that is being generated by the PHP script.  It looks like the PHP script is generating a <table> tag, but is not generating any <th> or <td> tags.  You can inspect the generated HTML document by using "view source" in your browser.

If you're new to PHP and web development and you want to find some good learning resources, this article contains links to the basic concepts as well as well-vetted information sources that can help you get going, and more importantly, can steer you away from the terrible examples that often litter the internet.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this tutorial viewers will learn how to style rounded corners for elements in CSS using the border-radius property Begin with a normal styled element such as a div: To style all four corners of the div to be the same degree of roundness, use the …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question