[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 77
  • Last Modified:

Losing My Head(ers)

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
DS928
Asked:
DS928
  • 4
  • 3
1 Solution
 
Marco GasiFreelancerCommented:
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
 
DS928Author Commented:
Perfect!  You have been such a big help!  Thank you!
0
 
Marco GasiFreelancerCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
DS928Author Commented:
Yes, I do have some knowledge, but in many ways I am still a beginner.  So your help is greatly appreciated!
0
 
Marco GasiFreelancerCommented:
Good luck with your project, then!
0
 
DS928Author Commented:
Thank you!  I think the inclusion of the PHP is throwing me off. :)
0
 
Marco GasiFreelancerCommented:
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now