Solved

Losing My Head(ers)

Posted on 2015-01-25
7
69 Views
Last Modified: 2015-01-25
I have my table being created, but I don't have my Headers, they seem to be in with the rows.  How can I fix This?
if ($conn->connect_error) {
    			die("Connection failed: " . $conn->connect_error);
			} 

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

			if ($result->num_rows > 0) {
    		// output data of each row
  			echo '<table>';
    		while($row = $result->fetch_assoc()) {
				echo "<tr class='viewpost'>";
  			if(!empty($row['recordId'])) {
      			echo '<td>Record ID: ' . $row['recordId'] . '</td>';
    			}
					else
					{
      			echo '<td>Record ID: NA</td>';
					}
  			if(!empty($row['recordCust'])) {
      			echo '<td>Customer' . $row['recordCust'] . '</td>';
    			}
					else
					{
      			echo '<td>Customer: NA</td>';
					}
  			if(!empty($row['recordSite'])) {
      			echo '<td>Site' . $row['recordSite'] . '</td>';
   	 			}
					else
					{
      			echo '<td>Site: NA</td>';
					}
    		if(!empty($row['recordUser'])) {
      			echo '<td>User Name' . $row['recordUser'] . '</td>';
   	 			}
					else
					{
      			echo '<td>User Name: NA</td>';
					}
			if(!empty($row['recordPass'])) {
      			echo '<td>Password' . $row['recordPass'] . '</td>';
   	 			}
					else
					{
      			echo '<td>Password: NA</td>';
					}
			if(!empty($row['recordDateAdded'])) {
      			echo '<td>Date Added' . $row['recordDateAdded'] . '</td>';
   	 			}			
					else
					{
      			echo '<td>Date Added: NA</td>';
					}
					echo "</tr>"; //closing row
				}
  			echo '</table>';

Open in new window


The headers are:
Record ID
Customer
Site
User Name
Password
Date Added
0
Comment
Question by:DS928
  • 4
  • 3
7 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 40569348
I guess you want something like this:

if ($conn->connect_error) {
    			die("Connection failed: " . $conn->connect_error);
			} 

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

			if ($result->num_rows > 0) {
    		// output data of each row
  			echo '<table>';
				echo "<thead>";//open teùable headers
				echo "<tr><th></th>Record ID<th>Customer</th><th>Site</th><th>User Name</th><th>Password</th><th>Date Added</th></tr>";
				echo "</thead>";//close headers row
				echo "<tbody>";//open table body
    		while($row = $result->fetch_assoc()) {
				echo "<tr class='viewpost'>";
  			if(!empty($row['recordId'])) {
      			echo '<td>' . $row['recordId'] . '</td>';
    			}
					else
					{
      			echo '<td>NA</td>';
					}
  			if(!empty($row['recordCust'])) {
      			echo '<td>' . $row['recordCust'] . '</td>';
    			}
					else
					{
      			echo '<td>NA</td>';
					}
  			if(!empty($row['recordSite'])) {
      			echo '<td>' . $row['recordSite'] . '</td>';
   	 			}
					else
					{
      			echo '<td>NA</td>';
					}
    		if(!empty($row['recordUser'])) {
      			echo '<td>' . $row['recordUser'] . '</td>';
   	 			}
					else
					{
      			echo '<td>NA</td>';
					}
			if(!empty($row['recordPass'])) {
      			echo '<td>' . $row['recordPass'] . '</td>';
   	 			}
					else
					{
      			echo '<td>NA</td>';
					}
			if(!empty($row['recordDateAdded'])) {
      			echo '<td>' . $row['recordDateAdded'] . '</td>';
   	 			}			
					else
					{
      			echo '<td>NA</td>';
					}
					echo "</tr>"; //closing row
				}
  			echo '</tbody>';
  			echo '</table>';

Open in new window

0
 

Author Closing Comment

by:DS928
ID: 40569368
Perfect!  You have been such a big help!  Thank you!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40569376
Forgive my curiosity, but I see from your history here at EE that you're questioning about css, javascript and the rest in the last two years. so I would expect you have some knowledge about these stuffs... but your doubt about HTML tables are typical of a total beginner, so I think I'm missing something :-)
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:DS928
ID: 40569391
Yes, I do have some knowledge, but in many ways I am still a beginner.  So your help is greatly appreciated!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40569395
Good luck with your project, then!
0
 

Author Comment

by:DS928
ID: 40569401
Thank you!  I think the inclusion of the PHP is throwing me off. :)
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40569404
I can suggest you this wonderful book which will help you to integrate php, mysql and html:
http://www.sitepoint.com/books/phpmysql5/
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

As a result of several questions about how to use Bootstrap I thought it would be a good idea to write down the development aspect of creating a Bootstrapped website in as little time as possible. Part 1 of this article will only concentrate on g…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
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 …

911 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

21 Experts available now in Live!

Get 1:1 Help Now