SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I have about 60 input boxes where the user can input a value 1 through 3. I am going to insert all of the values into a DB. When the administrator checks a certain persons values out, I need to make the places where the people put a 3 stand out.

    Only certain fields need to be checked if they have a 3. How do I change the color of the output if the value is three without going through a bunch of if...else statements.

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do it using CSS and outputting the variable twice.

    In your header or your linked CSS document define a class called 3

    Code:
    .3 {text-decoration: none; color: red; etc etc}
    Then in you're output do this (example is cold fusion, but can easily be adapted to any other language):

    Code:
    <CFOUTPUT QUERY = "Queryname">
    <td class = "#field1#">#field1#</td>
    <td class = "#field2#">#field2</td>
    etc
    etc
    etc
    </CFOUTPUT>
    This method will of course also let you define the display values if the entry is 1 or 2, if you so desire.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    So how could I do that in PHP? ereg()?

  4. #4
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You just do it like I did it in ColdFusion. You define the CSS class then print the DB variable out twice for each cell, once as the actually info, once to define the class:

    Code:
    while ( $row = mysql_fetch_array($result) ) 
    {    
    print("
    <td class = "$row[field1]">$row[field1]</td>
    <td class = "$row[field2]">$row[field2]</td>
    etc
    etc
    etc
    ");
    
    }
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  5. #5
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I am still lost.

    Say I have 2 input boxes, one named Name and the other Age. The user inputs 1 for name and 3 for age. Well on the administration page the admin can see the values that the user put in, if one of the values is 3 then the 3 is output with the color of red.

  6. #6
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    No one?

  7. #7
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I take it you don't have much experience with CSS.

    I guess you'll just have to trust me. Doing what I outlined will make all the 3's appear red, and it is the simplest and most efficient way to do it.

    so again. put this in the head of your document:

    Code:
    <STYLE>
    .3 {color: red;}
    </STYLE>
    Then when outputting the variables do what I outlined above and output the variable twice, once as the content, once as the class.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  8. #8
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    I have experience with CSS but I don't see where you are outputting the variable twice.

  9. #9
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,939
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    while ( $row = mysql_fetch_array($result) ) 
    {    
    print("
    <td class = "$row[field1]">$row[field1]</td>
    <td class = "$row[field2]">$row[field2]</td>
    etc
    etc
    etc
    ");
    
    }
    The red text is where the variable is outputted the first time. This value will be 1, 2, or 3. If it is a 1 or a 2 nothing will happen since there is no class defined for 1 or 2. But if it is a 3 it will access the class that is defined for 3 and color the text in that cell red.

    The blue text is the cell content. This is the second place where the variable will be outputted. And because of the reasons stated above, if this value is 3 it will be red.

    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  10. #10
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Note that, to adhere to standards, the above code should be modified so that the CSS class name does not start with a numeral. This can cause problems in standards-sensitive browsers like NS6 and Opera (although I haven't tested this particular issue with those browsers).
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  11. #11
    chown linux:users\ /world Hartmann's Avatar
    Join Date
    Aug 2000
    Location
    Houston, TX, USA
    Posts
    6,455
    Mentioned
    11 Post(s)
    Tagged
    0 Thread(s)
    Ok I got it now! And since it will only be used with IE5+ it should be ok right?

  12. #12
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    As long as you never plan to use JavaScript to alter the style definitions (which is impossible to do if those styles have a numerical name, since JavaScript can't handle this), you should be fine.

    Making your page standards-compliant would require minimal effort, however:

    Code:
    <STYLE>
    .a3 {color: red;}
    </STYLE>
    
    ...
    
    while ( $row = mysql_fetch_array($result) ) 
    {    
    print("
    <td class = "a$row[field1]">$row[field1]</td>
    <td class = "a$row[field2]">$row[field2]</td>
    etc
    etc
    etc
    ");
    
    }
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


Bookmarks

Posting Permissions

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