[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Formatting PHP Table

Posted on 2015-01-24
5
Medium Priority
?
89 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

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

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.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

650 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