3 Replies - 466 Views - Last Post: 13 August 2012 - 06:30 AM

#1 ThatUselessMan  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 16
  • Joined: 23-February 12

Table facing wrong way

Posted 13 August 2012 - 04:33 AM

Hey, I've been making something lately and when I'm trying to make a table, the headers are going to the left but I want them on the top. How do I change it/

Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['username'] . "</td> "; 
 Print "<th>Money:</th> <td>".$info['money'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?> 


Ignore the PHP in there, I'm just trying to call a players username and money, it works, but it looks like this
http://gyazo.com/f5c...a115c4f7833662e

Is This A Good Question/Topic? 0
  • +

Replies To: Table facing wrong way

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Table facing wrong way

Posted 13 August 2012 - 06:26 AM

the structure of an HTML table:
<table>
  <thead>
    <tr>
      <th>Header 1st column</th>
      <th>Header 2nd column</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td>Footer 1st column</td>
      <td>Footer 2nd column</td>
    </tr>
  </tfood>
  <tbody>
    <tr>
      <td>Content row 1 col 1</td>
      <td>Content row 1 col 2</td>
    </tr>
  </tbody>
</table>

Was This Post Helpful? 1
  • +
  • -

#3 DarenR  Icon User is offline

  • D.I.C Lover

Reputation: 434
  • View blog
  • Posts: 3,013
  • Joined: 12-January 10

Re: Table facing wrong way

Posted 13 August 2012 - 06:29 AM

View PostThatUselessMan, on 13 August 2012 - 07:33 AM, said:

Hey, I've been making something lately and when I'm trying to make a table, the headers are going to the left but I want them on the top. How do I change it/

Print "<table border cellpadding=3>"; 
 while($info = mysql_fetch_array( $data )) 
 { 
 Print "<tr>"; 
 Print "<th>Name:</th> <td>".$info['username'] . "</td> "; 
 Print "<th>Money:</th> <td>".$info['money'] . " </td></tr>"; 
 } 
 Print "</table>"; 
 ?> 


Ignore the PHP in there, I'm just trying to call a players username and money, it works, but it looks like this
http://gyazo.com/f5c...a115c4f7833662e




this is because you are telling it to go in that direction.

Putting the <td> tag after your php call that is right after your table heading aligns the objects in a row.

you will need to make a row with just the table headings

example
<tr><td><th>Name</th></td><td><th>Name</th></td></tr>
<tr><td>your php call here</td><td>your other php call</td></tr>


hope this helps
Was This Post Helpful? 1
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3494
  • View blog
  • Posts: 10,072
  • Joined: 08-June 10

Re: Table facing wrong way

Posted 13 August 2012 - 06:30 AM

HTML will allow you to omit some of said table elements, but when the table is parsed by the rendering engine, those elements will be created. if there is a conflict to the DTD, the browser will make an educated guess to render the table in a valid way.

View PostDarenR, on 13 August 2012 - 03:29 PM, said:

you will need to make a row with just the table headings

example
<tr><td><th>Name</th></td><td><th>Name</th></td></tr>
<tr><td>your php call here</td><td>your other php call</td></tr>


hope this helps

first line without the <td>s, of course.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1