• Status: Solved
  • Priority: High
  • Security: Public
  • Views: 45
  • Last Modified:

Problem with alignment in table

Need help with a table in php.  I'm trying to do a table that has a header on the top ("Other remarks"). This is going to followed by the data.  The columns are all being justfied to the right and the header is not centered.  I've attached the code. I can see why this doesn't work.
wtf.php
0
breeze351
Asked:
breeze351
  • 2
1 Solution
 
gr8gonzoConsultantCommented:
First, you have several HTML validity issues.
If you want to use HTML 5, just use "<!DOCTYPE html>" as your doctype:
<!DOCTYPE html>
<html>

Open in new window


Next, you've put all your content OUTSIDE your <body> block, which can cause some weird behavior for sure. It should look more like this:
<body>
<?php
$work = "in1";
echo '<table width = "100%" align = "left" id="Table3" style="border: 1px  solid black">';
echo "<tr>";
	 echo '<td width = 100% class = "Space_Display" align="center"> Other Remarks<td></tr>';
	 echo "<tr>";
	 	echo '<td width = 10% class = "Space_Display" align="left"> In-House<td>';
			echo '<td width = 30% align = "left">';
				if ($Display == "D")
				{
					echo $work;
				}
				else
				{
					echo '<input type="text" class = "k1" name="In_Remark1" size = "60" value="';
					echo $work;
					echo '" maxlenghth="60" title="In-House Remarks Line 1">';
 				}
			echo "</td>";

echo '<td width = 10%>';
echo "gd";
echo '</td>';



echo '<td width = 15% class = "Space_Display" align="left"> Private<td>';
echo '<td width = 30%>';
echo 'Fred Private</td>';
echo "</tr>";
?>
</table>
</body>
</html>

Open in new window


Next, you should add quotes around your width values, like this:
<td width="50%">


Next, you have several instances where your closing </td> tag is actually "<td>" instead of "</td>"
echo '<td width = 100% class = "Space_Display" align="center"> Other Remarks<td></tr>';

echo '<td width = 10% class = "Space_Display" align="left"> In-House<td>';

echo '<td width = 15% class = "Space_Display" align="left"> Private<td>';

Next, you should really try to stay consistent with your line breaks when you're building your table rows and cells. Don't do this:
<tr>
  <td>content A</td></tr>
<tr><td>content B</td></tr>
<tr>
  <td>content C</td>
</tr>

Pick one format and stick with it to make your code easier to read in the future. If you have multiple columns (which is usually the case), I recommend putting <tr> and </tr> on their own lines, and then each <td></td> on its own line, like this:

<tr>
  <td>content</td>
  <td>content</td>
  <td>content</td>
</tr>

Next, you have a misspelling in "maxlength", which will probably cause confusion if you don't correct it.

Finally, your first row has only one column, and your next row has 5 columns. You should use colspan on the first row's <td> to indicate how many columns that should take up. For example:

echo "<tr>";
       echo '<td width = 100% class = "Space_Display" align="center" colspan="5"> Other Remarks</td></tr>';
2
 
breeze351Author Commented:
Thanks.  Got it.
0
 
breeze351Author Commented:
Got it
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

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