Table Column Width

My table just isn’t doing what I would like it to do. How do I control the width of each column? I have tried putting the width attribute after the td tag but it does not appear to make any difference.
I would also like to have control of the alignment.

<tr> <td width="20"><div align="center"><input value="<?php echo $row_Orders['OrderNumber']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['OrderDate']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['RequiredDate']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['Code']; ?>"></div></td> <td><div align="left"><input value="<?php echo $row_Orders['Customer']; ?>"></div></td> <td><div align="left"><input value="<?php echo $row_Orders['Part']; ?>"></div></td> <td><div align="left"><input value="<?php echo $row_Orders['Description']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['Qty']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['Freight']; ?>"></div></td> <td><div align="center"><input value="<?php echo $row_Orders['Supplier']; ?>"></div></td>

Thanks for any help.

Your code looks totally incorrect to me.

AFAIK putting a div inside a table is not a good idea

Have a look at this http://www.w3schools.com/tags/tag_td.asp

In your first line you have width=“20”, 20 what % or px for example.

Valkrider,
Thanks for the reply. I have changed the code a bit and removed the div tag. Still no change in the result.

[code] <?php do { ?>













<?php } while ($row_Orders = mysql_fetch_assoc($Orders)); ?> [/code]

You haven’t removed the closing div tags

Give this a try

<td width="20px"><?php echo $row_Orders['OrderNumber']; ?></td>

I saw that after I sent the post, but still hasn’t made any difference. Does the

control this attribute? Here is my table in complete just in case.

[code]

<?php do { ?>
<tr>
  <td width="50px" align="center"><input value="<?php echo $row_Orders['OrderNumber']; ?>"></td>
  <td width="20px"><input value="<?php echo $row_Orders['OrderDate']; ?>"></td>
  <td width="20px"><input value="<?php echo $row_Orders['RequiredDate']; ?>"></td>
  <td width="20px"><input value="<?php echo $row_Orders['Code']; ?>"></td>
  <td width="100px"><input value="<?php echo $row_Orders['Customer']; ?>"></td>
  <td width="100px"><input value="<?php echo $row_Orders['PartCode']; ?>"></td>
  <td><input value="<?php echo $row_Orders['PartDescription']; ?>"></td>
  <td><input value="<?php echo $row_Orders['PartQty']; ?>"></td>
  <td><input value="<?php echo $row_Orders['Freight']; ?>"></td>
  <td><input value="<?php echo $row_Orders['Supplier']; ?>"></td>
</tr>
<?php } while ($row_Orders = mysql_fetch_assoc($Orders)); ?>
Order No. Order Date Required Date Code Customer Part Description Qty Freight Supplier
[/code]

hi Valkrider,
I removed the input tag and the code below works. I am trying to make this form editable by the user so that they can make changes to their order if they need to. I just seem to lose control of the formatting when the field become text inputs. Any ideas?

<tr> <td width="70"><div align="center"><?php echo $row_Orders['OrderNumber']; ?></div></td> <td width="80"><div align="center"><?php echo $row_Orders['OrderDate']; ?></div></td> <td width="120"><div align="center"><?php echo $row_Orders['RequiredDate']; ?></div></td> <td width="15"><div align="center"><?php echo $row_Orders['Code']; ?></div></td> <td><div align="left"><?php echo $row_Orders['Customer']; ?></div></td> <td><div align="left"><?php echo $row_Orders['PartCode']; ?></div></td> <td><div align="left"><?php echo $row_Orders['PartDescription']; ?></div></td> <td width="30"><div align="center"><?php echo $row_Orders['PartQty']; ?></div></td> <td width="15"><div align="center"><?php echo $row_Orders['Freight']; ?></div></td> <td width="15"><div align="center"><?php echo $row_Orders['Supplier']; ?></div></td> </tr>

I create my forms using pure CSS, tables are supposed to be only used for tabular data and what you are doing is not what tables are intended for.

th is table header and is used in the first row to designate your column names.

To give you an example this is a piece of code from one of my sites where it displays the MySQL field names as the column names in the first row of the table. This table is purely for data display and not edit.

[php]

<?php $result = mysql_query("SELECT * FROM {$table}"); if (!$result) { die("Query to show fields from table failed"); } $fields_num = mysql_num_fields($result); echo ""; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "\n"; ?>

[/php]

{$field->name}"; } echo "

Thanks V,
I have rewritten this section and have gone with the CSS as you suggested. I always thought it was the better option but not used CSS much.
Appreciate you comments.
cracker

Sponsor our Newsletter | Privacy Policy | Terms of Service