-2

I'm working on getting an html table up on my site. It pulls some info from an mssql database. I'm trying to find a way to display the table best, because it's a pretty big table. I first tried just putting one long horizontal table, but it took up 3 times the screen. I then tried doing it in multiple rows, but I found that it would look bad if there were multiple records in the table.

I'm now trying to do a vertical table, but I can't figure out how to make it so the rows in the table are level with each other.

Here's my code:

echo "<table border='1'>
<td>
<table><tr><th>Name of Center</th></tr></table>
<table><tr><th>Contact Name</th></tr></table>
<table><tr><th>Title</th></tr></table>
<table><tr><th>Street Address</th></tr></table>
<table><tr><th>City</th></tr></table>
<table><tr><th>State</th></tr></table>
<table><tr><th>Zipcode</th></tr></table>
<table><tr><th>Phone</th></tr></table>
<table><tr><th>Fax</th></tr></table>
<table><tr><th>Email</th></tr></table>
<table><tr><th>Director</th></tr></table>
<table><tr><th>HA 1</th></tr></table>
<table><tr><th>Address 1</th></tr></table>
<table><tr><th>Phone 1</th></tr></table>
<table><tr><th>HA 2</th></tr></table>
<table><tr><th>Address 2</th></tr></table>
<table><tr><th>Phone 2</th></tr></table>
<table><tr><th>HA 3</th></tr></table>
<table><tr><th>Address 3</th></tr></table>
<table><tr><th>Phone 3</th></tr></table>
<table><tr><th>Number of Years Operational</th></tr></table>
<table><tr><th>Annually</th></tr></table>
<table><tr><th>Coverage Limit</th></tr></table>
<table><tr><th>Coverage Deductible</th></tr></table>
<table><tr><th>2012</th></tr></table>
<table><tr><th>2011</th></tr></table>
<table><tr><th>2010</th></tr></table>
<table><tr><th>2012</th></tr></table>
<table><tr><th>2011</th></tr></table>
<table><tr><th>2010</th></tr></table>
<table><tr><th>Paid 2012</th></tr></table>
<table><tr><th>Paid 2011</th></tr></table>
<table><tr><th>Paid 2010</th></tr></table>
<table><tr><th>Instructions</th></tr></table>
</td>";

while($row = mssql_fetch_array($result)) {
  echo "<td>";
  echo "<table><tr>" . $row['Name_of_Center'] . "</tr></table>";
  echo "<table><tr>" . $row['Contact_Name'] . "</tr></table>";
  echo "<table><tr>" . $row['Title'] . "</tr></table>";
  echo "<table><tr>" . $row['Street_Address'] . "</tr></table>";
  echo "<table><tr>" . $row['City'] . "</tr></table>";
  echo "<table><tr>" . $row['State'] . "</tr></table>";
  echo "<table><tr>" . $row['Zipcode'] . "</tr></table>";
  echo "<table><tr>" . $row['Phone'] . "</tr></table>";
  echo "<table><tr>" . $row['Fax'] . "</tr></table>";
  echo "<table><tr>" . $row['Email'] . "</tr></table>";
  echo "<table><tr>" . $row['Director'] . "</tr></table>";
  echo "<table><tr>" . $row['HA1'] . "</tr></table>";
  echo "<table><tr>" . $row['HA1_Address'] . "</tr></table>";
  echo "<table><tr>" . $row['HA1_Phone'] . "</tr></table>";
  echo "<table><tr>" . $row['HA2'] . "</tr></table>";
  echo "<table><tr>" . $row['HA2_Address'] . "</tr></table>";
  echo "<table><tr>" . $row['HA2_Phone'] . "</tr></table>";
  echo "<table><tr>" . $row['HA3'] . "</tr></table>";
  echo "<table><tr>" . $row['HA3_Address'] . "</tr></table>";
  echo "<table><tr>" . $row['HA3_Phone'] . "</tr></table>";
  echo "<table><tr>" . $row['No_of_Years_Operational'] . "</tr></table>";
  echo "<table><tr>" . $row['Annually'] . "</tr></table>";
  echo "<table><tr>" . $row['Coverage_Limit'] . "</tr></table>";
  echo "<table><tr>" . $row['Coverage_Deductible'] . "</tr></table>";
  echo "<table><tr>" . $row['Donors_2012'] . "</tr></table>";
  echo "<table><tr>" . $row['Donors_2011'] . "</tr></table>";
  echo "<table><tr>" . $row['Donors_2010'] . "</tr></table>";
  echo "<table><tr>" . $row['Claims_2012'] . "</tr></table>";
  echo "<table><tr>" . $row['Claims_2011'] . "</tr></table>";
  echo "<table><tr>" . $row['Claims_2010'] . "</tr></table>";
  echo "<table><tr>" . $row['Paid_2012'] . "</tr></table>";
  echo "<table><tr>" . $row['Paid_2011'] . "</tr></table>";
  echo "<table><tr>" . $row['Paid_2010'] . "</tr></table>";
  echo "<table><tr>" . $row['Instructions'] . "</tr></table>";
  echo "</td>";
  }
echo "</table>";
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
marrrrrv
  • 29
  • 1
  • 7
  • Why are you putting all those ``s in each row?
    – andrewsi Apr 29 '14 at 15:23
  • 1
    I think you should read this before constructing your table : http://www.w3schools.com/html/html_tables.asp – PoulsQ Apr 29 '14 at 15:23
  • For some reason I was under the impression that you need to put if you're putting a inside a
    . Is this incorrect?
    – marrrrrv Apr 29 '14 at 15:25
  • @user2755449 - you can put your output directly inside a `` or `` tag; you don't need to wrap it further. If you add another `` tag, you'll end up wrapping it in a second table, which I don't think you want in this case.
    – andrewsi Apr 29 '14 at 15:27
  • @PoulsQ, I understand how to make a basic table. Do you misunderstand my question, or am I overlooking something simple? – marrrrrv Apr 29 '14 at 15:28
  • 2
    Seeing as your table HTML is very wrong, then with all due respect - but I do not think you understand how to make a basic table. I'd also recommend checking on w3schools and then readdressing your code afterwards, once you know how your table should look - then it's much easier to actually code the output. – Allan S. Hansen Apr 29 '14 at 15:28
  • Found the answer here: http://stackoverflow.com/questions/6368061/most-common-way-of-writing-a-html-table-with-vertical-headers – marrrrrv Apr 29 '14 at 15:41

1 Answers1

0

You only need one table tag per table, use multiple tr and td within the table and you'll find that it will all become level.

As mentioned, read this and it will help http://www.w3schools.com/html/html_tables.asp

samgbelton
  • 89
  • 1
  • 10
  • Thanks, but no thanks. No where on that page does it show how to do vertical headers/tables. Linking someone to a page where all it shows is basic information is simply not a good answer. I don't understand why this community believes this, and gives people rep for doing so. If you can't answer the question, then don't say anything. – marrrrrv Apr 29 '14 at 15:49
  • I apologise if you did not find my answer helpful but with all due respect it looked as if you were struggling to build the table correctly. w3schools helps me greatly with these sorts of things. – samgbelton Apr 29 '14 at 16:04