Table format needs php correction

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default Table format needs php correction

    Hi!

    This is a problem of the table formatting on a form in MySQL and PHP.
    It may be in the HTML table code.

    The problem is one that must be frequent. I have a mixture of one character
    and long fill-in text items.

    My table now looks awkward. Somebody gave me a complex table that puts colors as backgrounds
    behind the headers. Could that be the problem? -Gloria


    Here is the URL to view PHP HTML table as it appears on screen:
    [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]

    Here is the mysql create table structure file:

    #
    # Table structure for table 'CAT'
    #

    CREATE TABLE CAT (
    id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
    added datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    name varchar(50) NOT NULL,
    course varchar(50) NOT NULL,
    unit varchar(50) NOT NULL,
    q1 text NOT NULL,
    q2 text NOT NULL,
    q3 text NOT NULL,
    q4 text NOT NULL,
    q5 varchar(10) NOT NULL,
    q6 varchar(10) NOT NULL,
    q7 varchar(10) NOT NULL,
    PRIMARY KEY (id)
    );


    Here is the table HTML part of the PHP file:

    print "<table>\n";
    while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    print "\t<tr>\n";
    foreach ($line as $col_value) {
    print "\t\t<td>$col_value</td>\n";
    }
    print "\t</tr>\n";
    }
    print "</table>\n";
    */
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    printf("
    <div class=\"colorfield\">
    <table>
    <tr><th>Date</th><th>Name</th><th>Course</th><th>Unit</th>\n

    <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n

    <tr><th = colspan = 4> Q1 </th>\n
    <tr><td>%s</td>\n

    <tr><th = colspan = 4> Q2 </th>\n
    <tr><td>%s</td>\n

    <tr><th = colspan = 4> Q3 </th>\n
    <tr><td>%s</td>\n

    <tr><th = colspan = 4> Q4 </th>\n
    <tr><td>%s</td>\n

    <tr><th>Q5</th><th>Q6</th><th>Q7</th>\n

    <tr><td>%s</td><td>%s</td><td>%s</td>\n
    </table>


    </div>\n",
    $row['added'],
    $row['name'],
    $row['course'],
    $row['unit'],
    $row['q1'],
    $row['q2'],
    $row['q3'],
    $row['q4'],
    $row['q5'],
    $row['q6'],
    $row['q7']);

    }

    /* Free resultset */
    mysql_free_result($result);

    /* Close the database connection */
    mysql_close($link);

    ?>
    </body>
    </html>
    Gloria L. McMillan Guest

  2. Similar Questions and Discussions

    1. Table Format
      Is it possible to modify Contribute's predetermined table formats so that only table styles contained within the style sheet can be used?
    2. Table won't format...why?
      I am a newbie, kind of. I had a dreamweaver class a few years ago, but can't remember much. I am trying to format a table so it fits the whole...
    3. ACT (color table) file format
      I have color information (data sets read from a spectrophotometer) that I need to get into an ACT (color table) file. I am looking for the file...
    4. Table Format and Properties
      Hello, I have made a table and ironed out some of the glitches with it. Thanks for help before on that (I bizarrely posted the Q's in the...
    5. exporting a table for a format txt
      I need to create a form of exporting a table for a format txt. I know that can create a macro for that and tie I already did. Only that to macro...
  3. #2

    Default Re: [PHP] Table format needs php correction

    On Sat, 30 Aug 2003 10:23:49 -0700
    "Gloria L. McMillan" <glomc@DakotaCom.net> wrote:
    > Hi!
    >
    > This is a problem of the table formatting on a form in MySQL and PHP.
    > It may be in the HTML table code.
    >
    > The problem is one that must be frequent. I have a mixture of one
    > character and long fill-in text items.
    >
    > My table now looks awkward. Somebody gave me a complex table that puts
    > colors as backgrounds behind the headers. Could that be the problem?
    > -Gloria
    The SQL has nothing to do with it (though make sure the query returns
    what you expect), it's just how you format the table with the data you
    have. My advice is to start it simple with no colors or stuff like that
    and work on it until you get the proper table (html). Forget about using
    other people's code in something like this and try to understand the
    logic before you get to beautifying your output. I just spent the last
    couple of days with tables formating, css, etc....
    >
    >
    > Here is the URL to view PHP HTML table as it appears on screen:
    > [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    >
    > Here is the mysql create table structure file:
    >
    > #
    > # Table structure for table 'CAT'
    > #
    >
    > CREATE TABLE CAT (
    > id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
    > added datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    > name varchar(50) NOT NULL,
    > course varchar(50) NOT NULL,
    > unit varchar(50) NOT NULL,
    > q1 text NOT NULL,
    > q2 text NOT NULL,
    > q3 text NOT NULL,
    > q4 text NOT NULL,
    > q5 varchar(10) NOT NULL,
    > q6 varchar(10) NOT NULL,
    > q7 varchar(10) NOT NULL,
    > PRIMARY KEY (id)
    > );
    >
    >
    > Here is the table HTML part of the PHP file:
    >
    > print "<table>\n";
    > while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    > print "\t<tr>\n";
    > foreach ($line as $col_value) {
    > print "\t\t<td>$col_value</td>\n";
    > }
    > print "\t</tr>\n";
    > }
    > print "</table>\n";
    > */
    > while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    > printf("
    > <div class=\"colorfield\">
    > <table>
    > <tr><th>Date</th><th>Name</th><th>Course</th><th>Unit</th>\n
    >
    > <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n
    >
    > <tr><th = colspan = 4> Q1 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q2 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q3 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q4 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th>Q5</th><th>Q6</th><th>Q7</th>\n
    >
    > <tr><td>%s</td><td>%s</td><td>%s</td>\n
    > </table>
    >
    >
    > </div>\n",
    > $row['added'],
    > $row['name'],
    > $row['course'],
    > $row['unit'],
    > $row['q1'],
    > $row['q2'],
    > $row['q3'],
    > $row['q4'],
    > $row['q5'],
    > $row['q6'],
    > $row['q7']);
    >
    > }
    >
    > /* Free resultset */
    > mysql_free_result($result);
    >
    > /* Close the database connection */
    > mysql_close($link);
    >
    > ?>
    > </body>
    > </html>
    >
    > --
    > PHP General Mailing List ([url]http://www.php.net/[/url])
    > To unsubscribe, visit: [url]http://www.php.net/unsub.php[/url]
    >
    >
    >

    --
    Regards, Andu Novac
    Andu Guest

  4. #3

    Default Re: Table format needs php correction

    There are too many problems with your code for anyone to spend the time
    going thru them all.

    I'd suggest, first constructing a regular html table that looks like you
    want it to. Hint, IE6 requires something in TDs [e.g., &nbsp;] for
    borders to show.

    When the table looks the way you want it to, validate the code at
    [url]http://validator.w3.org/[/url]

    Then work on your php code to generate the exact same html.

    Gloria L. McMillan wrote:
    >Hi!
    >
    >This is a problem of the table formatting on a form in MySQL and PHP.
    >It may be in the HTML table code.
    >
    >The problem is one that must be frequent. I have a mixture of one character
    >and long fill-in text items.
    >
    >My table now looks awkward. Somebody gave me a complex table that puts colors as backgrounds
    >behind the headers. Could that be the problem? -Gloria
    >
    >
    >Here is the URL to view PHP HTML table as it appears on screen:
    >[url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    >
    >Here is the mysql create table structure file:
    >
    >#
    ># Table structure for table 'CAT'
    >#
    >
    >CREATE TABLE CAT (
    > id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
    > added datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
    > name varchar(50) NOT NULL,
    > course varchar(50) NOT NULL,
    > unit varchar(50) NOT NULL,
    > q1 text NOT NULL,
    > q2 text NOT NULL,
    > q3 text NOT NULL,
    > q4 text NOT NULL,
    > q5 varchar(10) NOT NULL,
    > q6 varchar(10) NOT NULL,
    > q7 varchar(10) NOT NULL,
    > PRIMARY KEY (id)
    >);
    >
    >
    >Here is the table HTML part of the PHP file:
    >
    >print "<table>\n";
    >while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    > print "\t<tr>\n";
    > foreach ($line as $col_value) {
    > print "\t\t<td>$col_value</td>\n";
    > }
    > print "\t</tr>\n";
    >}
    >print "</table>\n";
    >*/
    >while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    > printf("
    ><div class=\"colorfield\">
    ><table>
    > <tr><th>Date</th><th>Name</th><th>Course</th><th>Unit</th>\n
    >
    ><tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n
    >
    > <tr><th = colspan = 4> Q1 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q2 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q3 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th = colspan = 4> Q4 </th>\n
    > <tr><td>%s</td>\n
    >
    > <tr><th>Q5</th><th>Q6</th><th>Q7</th>\n
    >
    > <tr><td>%s</td><td>%s</td><td>%s</td>\n
    ></table>
    >
    >
    ></div>\n",
    > $row['added'],
    > $row['name'],
    > $row['course'],
    > $row['unit'],
    > $row['q1'],
    > $row['q2'],
    > $row['q3'],
    > $row['q4'],
    > $row['q5'],
    > $row['q6'],
    > $row['q7']);
    >
    >}
    >
    >/* Free resultset */
    > mysql_free_result($result);
    >
    >/* Close the database connection */
    >mysql_close($link);
    >
    >?>
    ></body>
    ></html>
    >
    >
    Al Guest

  5. #4

    Default Re: [PHP] Table format needs php correction

    * Thus wrote Gloria L. McMillan (glomc@DakotaCom.net):
    > Hi!
    Hello Gloria,
    >
    > This is a problem of the table formatting on a form in MySQL and PHP.
    > It may be in the HTML table code.
    > ...
    > Here is the URL to view PHP HTML table as it appears on screen:
    > [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    I think you need to take a step back for a moment. First consider
    how you want the data to be presented in html, then the php code
    will be very simple.

    From what I see and how I would prefer to set the layout would be
    something like this:

    Date Name Course Unit
    Aug 30 2003 Gloria WRT 102 Fall 03 Essay 1

    Q1 data for q1
    Q2 data for q2
    ...


    Then easily put that into a html table structure:

    <tr>
    <td>Date</td><td>Name</td><td>Course</td><td>Unit</td>
    </tr>
    <tr>
    <td>Aug 30 2003</td><td>Gloria </td><td>WRT 102 Fall 03</td><td>Essay 1</td>
    </tr>
    <tr>
    <td>Q1</td><td colspan="3">data for q1</td>
    </tr>
    <tr>
    <td>Q2</td><td colspan="3">data for q2</td>
    <tr>
    ...

    Now inside your fetch_array loop just use that template above using
    php variables instead of text and table column attributes in the
    appropriate places will result in a decent looking site.


    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  6. #5

    Default Re: [PHP] Table format needs php correction

    * Thus wrote Curt Zirzow (php-general@zirzow.dyndns.org):
    > * Thus wrote Gloria L. McMillan (glomc@DakotaCom.net):
    > > Hi!
    >
    > Hello Gloria,
    >
    > >
    > > This is a problem of the table formatting on a form in MySQL and PHP.
    > > It may be in the HTML table code.
    > > ...
    > > Here is the URL to view PHP HTML table as it appears on screen:
    > > [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    >
    > I think you need to take a step back for a moment. First consider
    > how you want the data to be presented in html, then the php code
    > will be very simple.
    Ok, I had a little extra time this morning :)

    [url]http://zirzow.dyndns.org/html/php/html/table.php[/url]


    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

  7. #6

    Default Re: [PHP] Table format needs php correction

    Thanks but the lines are all running together in that URL.
    I don't know why.
    They are not breaking at the end of each line.

    Could you re-save a different way?
    Maybe send to me as a text file?

    Thanks,

    Gloria


    Curt Zirzow wrote:
    > * Thus wrote Curt Zirzow (php-general@zirzow.dyndns.org):
    > > * Thus wrote Gloria L. McMillan (glomc@DakotaCom.net):
    > > > Hi!
    > >
    > > Hello Gloria,
    > >
    > > >
    > > > This is a problem of the table formatting on a form in MySQL and PHP.
    > > > It may be in the HTML table code.
    > > > ...
    > > > Here is the URL to view PHP HTML table as it appears on screen:
    > > > [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    > >
    > > I think you need to take a step back for a moment. First consider
    > > how you want the data to be presented in html, then the php code
    > > will be very simple.
    >
    > Ok, I had a little extra time this morning :)
    >
    > [url]http://zirzow.dyndns.org/html/php/html/table.php[/url]
    >
    > Curt
    > --
    > "I used to think I was indecisive, but now I'm not so sure."
    Gloria L. McMillan Guest

  8. #7

    Default Re: [PHP] Table format needs php correction

    This is all so advanced. Is it ready to be in place of the table HTML that I already have?

    I copied it to word and saved it as a .txt file. IN IE it looked better than in my
    Netscape.

    Gloria


    Curt Zirzow wrote:
    > * Thus wrote Curt Zirzow (php-general@zirzow.dyndns.org):
    > > * Thus wrote Gloria L. McMillan (glomc@DakotaCom.net):
    > > > Hi!
    > >
    > > Hello Gloria,
    > >
    > > >
    > > > This is a problem of the table formatting on a form in MySQL and PHP.
    > > > It may be in the HTML table code.
    > > > ...
    > > > Here is the URL to view PHP HTML table as it appears on screen:
    > > > [url]http://DakotaCom.net/~glomc/forms/CAT.php[/url]
    > >
    > > I think you need to take a step back for a moment. First consider
    > > how you want the data to be presented in html, then the php code
    > > will be very simple.
    >
    > Ok, I had a little extra time this morning :)
    >
    > [url]http://zirzow.dyndns.org/html/php/html/table.php[/url]
    >
    > Curt
    > --
    > "I used to think I was indecisive, but now I'm not so sure."
    Gloria L. McMillan Guest

  9. #8

    Default Re: [PHP] Table format needs php correction

    * Thus wrote Gloria L. McMillan (glomc@DakotaCom.net):
    > This is all so advanced. Is it ready to be in place of the table HTML that I already have?
    >
    Yes it should be. I hope it isn't so advanced that you can't
    understand what exactly I'm doing. That would rather defeat the
    purpose of me writing that up.
    > I copied it to word and saved it as a .txt file. IN IE it looked better than in my
    > Netscape.
    My appologies for that, I havn't tested the site in mozilla/netscape
    yet, only IE and opera. I'm actually downloading mozilla right now.


    HTH,

    Curt
    --
    "I used to think I was indecisive, but now I'm not so sure."
    Curt Zirzow Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139