?
Solved

Formatting PHP Table

Posted on 2015-01-24
5
Medium Priority
?
84 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

800 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