?
Solved

Table Not Making Columns

Posted on 2015-01-24
3
Medium Priority
?
79 Views
Last Modified: 2015-01-25
This table is making one column only.  Should be six columns.  What am I doing wrong?
<style type=”text/css”>
.viewpost {
    border: 1.5px solid #367588;
    background-color: #333;
    margin-bottom:25px;
}

.viewpost1 {
    border: 1.5px solid #367588;
    background-color: #333;
    line-height:100px;
    vertical-align:top;
    margin-left:10px;
    }
</style>

Open in new window


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

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
3 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 2000 total points
ID: 40568932
First You're closing each row after wach column so you'll always have only one column per row. econd, I think it would be better if a value is empty printing omething like 'NA'.

Your style:
		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>';
    			}
  			if(!empty($row['recordCust'])) {
      			echo '<td>Customer ' . $row['recordCust'] . '</td>';
    			}
  			if(!empty($row['recordSite'])) {
      			echo '<td>Site ' . $row['recordSite'] . '</td>';
   	 			}
    		if(!empty($row['recordUser'])) {
      			echo '<td>User Name ' . $row['recordUser'] . '</td>';
   	 			}
			if(!empty($row['recordPass'])) {
      			echo '<td>Password ' . $row['recordPass'] . '</td>';
   	 			}
			if(!empty($row['recordDateAdded'])) {
      			echo '<td>Date Added ' . $row['recordDateAdded'] . '</td>';
   	 			}			
					echo "</tr>"; //closing row
				}
  			echo '</table>';

Open in new window


my suggesiton:
		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

0
 

Author Closing Comment

by:DS928
ID: 40569329
Thank you!
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 40569330
Glad to help you!
Cheers
0

Featured Post

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!

Question has a verified solution.

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

Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this tutorial viewers will learn how to customize the background color and font color of highlighted text using the ::selection element in CSS Begin by defining the selected text as an element in CSS by typing "::selection": Style the ::selection…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

777 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