0

I am trying to make a website that connects to the database that will save race information.

At the moment the columns are far too long even though I have set the length to 7 characters.

What is it I'm doing wrong? How do I get the width of the columns to be 7 characters long?

Here is my code:

<?php
    function table_head()
    {
        if ( func_num_args() > 0 )
        {
            $args = func_get_args();
            foreach($args as $value)
            {
                echo "<th>" . $value . "</th>";
            } 
        }
    }


    function display_fields()
    {
        $i = 0;
        $a = 19;
        while($i++ < $a)
        {
            echo "<td><input type='text' width='7'/></td>";
        } 
    }

    echo "<table>";
    echo "<col width='7'>";
    echo "<tr>";
    table_head("Time","lap1","lap2","lap3","lap4","lap5","lap6","lap7","lap8","lap9","lap10","lap11","lap12","lap13","lap14","lap15","lap16","lap17","Avg Spd");
    echo "</tr>";
    echo "<tr>";
    display_fields();
    echo "</tr>";
    echo "</table>";
?>

I know I can be more efficient with my code, I am going to make it more efficient soon.

Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
iProgram
  • 5,317
  • 8
  • 34
  • 74
  • I think this has been answered before: http://stackoverflow.com/questions/4457506/set-the-table-column-width-constant-regardless-of-the-amount-of-text-in-its-cell – Jason Holmberg Aug 18 '15 at 14:42

1 Answers1

2

You want to use the size attribute not width.

<input type="text" size="7">

The width attribute for <input> elements only works when the input's type is image.

<!-- Image input -->
<input type="image" width="300">
hungerstar
  • 20,438
  • 6
  • 45
  • 58