Solved

Formatting PHP Table

Posted on 2015-01-24
5
69 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 108

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 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

706 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now