Jump to content

[SOLVED] Help with HTML Tables


tqla

Recommended Posts

Hi. This script pulls data from a DB and displays it in an HTML tale:

$sql = "SELECT * FROM Clients ORDER BY CreatedOn DESC LIMIT 50";
$result = mysql_query($sql, $conn) or die (mysql_error());

while ($list = mysql_fetch_array($result)) {
echo '<table width=\"90%\" border=\"1\"><tr>';
echo '<td>'  .$list['CompanyName']. '</td>';
echo '<td>'  .$list['CreatedOn']. '</td>';
echo '<td>'  .$list[' FName']. '</td>';
echo '<td>'  .$list[' LName']. '</td>';
echo '<td>'  .$list['Contact']. '</td>';
echo '<td>'  .$list['MAddress']. '</td>';
echo '<td>'  .$list['MAddress2']. '</td>';
echo '<td>'  .$list['MCity']. '</td>';
echo '<td>'  .$list['MState']. '</td>';
echo '<td>'  .$list['MZip']. '</td>';
echo '<td>'  .$list['Phone']. '</td>';
echo '<td>'  .$list['Cell']. '</td>';
echo '<td>'  .$list['Email']. '</td>';
  }
echo '</tr></table>';

 

The problem is that the resulting table does not look the way I want it to. I want the table to look like a uniform table with 13 even columns and rows.

 

Right now a separate table is being created for each individual row and they are stacking on top of each other all uneven - some fiels are being stretched by content, etc...

 

How can I make this to be a 13 column table with all of the info stacked evenly?

 

Thanks!

Link to comment
Share on other sites

$sql = "SELECT * FROM Clients ORDER BY CreatedOn DESC LIMIT 50";
$result = mysql_query($sql, $conn) or die (mysql_error());

echo '<table width=\"90%\" border=\"1\">';
while ($list = mysql_fetch_array($result)) {
echo '<tr><td>'  .$list['CompanyName']. '</td>';
echo '<td>'  .$list['CreatedOn']. '</td>';
echo '<td>'  .$list[' FName']. '</td>';
echo '<td>'  .$list[' LName']. '</td>';
echo '<td>'  .$list['Contact']. '</td>';
echo '<td>'  .$list['MAddress']. '</td>';
echo '<td>'  .$list['MAddress2']. '</td>';
echo '<td>'  .$list['MCity']. '</td>';
echo '<td>'  .$list['MState']. '</td>';
echo '<td>'  .$list['MZip']. '</td>';
echo '<td>'  .$list['Phone']. '</td>';
echo '<td>'  .$list['Cell']. '</td>';
echo '<td>'  .$list['Email']. '</td></tr>';
  }
echo '</table>';

Link to comment
Share on other sites

AHA! I got it. I needed to move the opening <tabe> up like this:

echo '<table width=\"90%\" border=\"1\">';

while ($list = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>'  .$list['CompanyName']. '</td>';
echo '<td>'  .$list['CreatedOn']. '</td>';
echo '<td>'  .$list['FName']. '</td>';
echo '<td>'  .$list['LName']. '</td>';
echo '<td>'  .$list['Contact']. '</td>';
echo '<td>'  .$list['MAddress']. '</td>';
echo '<td>'  .$list['MAddress2']. '</td>';
echo '<td>'  .$list['MCity']. '</td>';
echo '<td>'  .$list['MState']. '</td>';
echo '<td>'  .$list['MZip']. '</td>';
echo '<td>'  .$list['Phone']. '</td>';
echo '<td>'  .$list['Cell']. '</td>';
echo '<td>'  .$list['Email']. '</td></tr>';
  }
echo '</table>';

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.