I am rather new to php and adding code php code to html. I wrote a php, which worked with no problem. After I added some html along with some css styles, it hasn't worked correctly. Pretty much, it ignores all my css codes. Will styles interfere with this in anyway? I have looked over my code more than enough times and it looks a ok to me. I have narrowed it down to this small section. Did I do this wrong?

<table style="border"> 
<tr> 
<td> 
<?php 
print "<table style="products">\n"; 
while ( $a_row = mysql_fetch_row( $record ) ) { 
   print "<tr>\n"; 
   foreach ( $a_row as $field ) 
      print "\t<td style="padding">$field</td>\n"; 
   print "</tr>\n"; 
} 
print "</table>\n"; 
mysql_close( $link ); 
?> 
</td> 
</tr> 
</table> 

The only thing that is different is from my first script is the table that surrounds everything and the styles. Thanks for your help.

    I think instead of "<TD STYLE="whatever"> it should be "<TD CLASS>. In addition, you may want to lose the quotes around "whatever" and just write "<TD CLASS=whatever>.

      Try this..

      <table style="border"> 
      <tr> 
      <td> 
      <?php 
      print "<table class=\"products\">\n"; 
      while ( $a_row = mysql_fetch_row( $record ) ) { 
         print "<tr>\n"; 
         foreach ( $a_row as $field ) 
            print "\t<td class=\"padding\">$field</td>\n"; 
         print "</tr>\n"; 
      } 
      print "</table>\n"; 
      mysql_close( $link ); 
      ?> 
      </td> 
      </tr> 
      </table>

        There are three ways to create CSS. Let's take a simple example of having the font color blue.

        INTERNAL WITHIN THE HTML FILE

        <head>
        <style type="text/css">
        color: blue;
        </style>
        </head>

        EXTERNAL OUTSIDE THE HTML FILE

        <link rel="stylesheet" type="text/css" href="myCssFile.css">

        myCssFile.css (external file)

        body { color: blue; }

        INLINE WITHIN THE HTML FILE USING STYLE TAG ATTRIBUTE

        <DIV style="color:blue">This should be blue</DIV>

        Note: This is a property/attribute pair and not a class or selector

        So if I am reading your question right, you are concerned with this latter approach (Style tag attribute).

        Or maybe you are new to CSS too?

        I am not sure that the other two responses are correct if your desire is to use the inline style tag attribute (which is what your PHP code shows). I believe those two approaches will force you to resort to using the internal or external approach.

        But I would not recommend using inline styling for several reasons. Inline styling forces you to decentralize all the styling information making it very difficult to manage. Imagine having thousands of HTML files with style information in it. What if you wanted to change the font color to orange? You'd have to go through every page and make the inline change.

        Another problem with the inline approach is that you also tightly bind the presentation and business logic into the file. Ideally you want to separate the two.

        If you want to use inline styling, the problem I believe in your code is that you are using a class selector when a property:value should be used.

        It's your call on how you want to do this but I'd recommend changing the approach.

        Hope this helps.

          To prove that your problem has nothing to do with PHP, study the two files and run it in your browser:

          Test1.html

          <html>
          <head>
          <title>Test</title>
          <style>
          .mytest
          {
          color: red;
          }
          </style>
          </head>

          <body>
          <div class="mytest">
          this is some red text
          </div>
          </body>

          </html>

          Test2.html

          <html>
          <head>
          <title>Test</title>
          <style>
          .mytest
          {
          color: red;
          }
          </style>
          </head>

          <body>
          <div style="mytest">
          this is some red text
          </div>
          </body>

          </html>

          I believe you are using the inline style tag attribute wrong. It is not meant to be used for classes or selectors but rather property:attribute pairs that I mentioned on the last message.

            This works.... see how property:value is used in the style attribute tag?

            <html>
            <head>
            <title>Test</title>
            </head>

            <body>
            <div style="color: red">
            this is some red text
            </div>
            </body>

            </html>

              In one of your posts (with the 2 test files), the Test2 didn't work. I know how to pass values with css (atleast I thought I did). I never had a problem until now. I just don't understand why it works on one php page, but not the other.

                Aha!

                Of course it doesnt work which is my point of all of this.

                Test2.html

                <html>
                <head>
                <title>Test</title>
                <style>
                .mytest <----------- class
                {
                color: red;
                }
                </style>
                </head>

                <body>
                <div style="mytest"> <---- trying to use a class with style attribute. THIS WONT WORK AND THIS IS WHAT YOU ARE TRYING TO DO.
                this is some red text
                </div>
                </body>

                </html>

                Isn't this what you are trying to do with the products class?

                The solution as I mentioned in the messages prior is to decide on what type of CSS you want to use:

                internal
                external
                inline

                Because you repeatedly said that you used Css before and knew what you were doing, I assumed that to be the case. However, I don't think you know how to use the inline version of Css?

                Thus, this has NOTHING to do with PHP.

                  I see what you are saying about the inline way. I have never used it before since I had no use for it. Ahhh. Yes, I see. My idea was to use external. I was just using internal for now because it was all on one page. If I understand correctly, inline uses property and attributes all in one line. My question would be what happens when I have 3 tables that all need to be different. I would have a lot of css to write. Each table would have its own border, color, text, etc set of values? Am I catching on yet? I wanted to have one global file (external file) where I could set all the values. You are saying this can't be done using what I have done so far? If you just show me a small example, that would be great. I think i'm starting to understand. Thanks.

                    I think its best for you to start off a new topic with your latest new question. You'll get more people (not just myself) to be able to respond to it.

                    From my assessment, your new question doesn't have anything to do with PHP programming as well...

                    It is more of a web design/Css/Html issue.

                      Thanks for your time. I'll see what I can learn about the inline way of css before I start a new topic. Any site that might have some useful stuff?

                        As mentioned in a previous message, it is NOT a good idea to use inline Css styling because it creates a horrible maintenance issue. Please reread the prior post.

                        Go to www.w3c.org and read the CSS1 and CSS2 areas for additional information.

                          Write a Reply...