Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts

    <?php if($important == 1){ class='mainrow1' } else {class='mainrow2} ?>

    how would i display <?php if($important == 1){ class='mainrow1' } else {class='mainrow2} ?> correctly... im not sure how to use classes within php ... or can it even be done?

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Classes as in html? Or classes as in object oriented php programming? I think you'll have to show us more code than that... Also, you didn't close the quotes on mainrow2.
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #3
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    basicly what i want to do is <?php if($important == 1){ class='mainrow1' } else {class='mainrow'} ?>

    so if my forum area is important make it red if not make it blue for example

    so

    if important == 1 do this .mainrow1 {font-family: Verdana,Sans-serif;color: #000000;background-color: #eeeeee;font-size: 12px; a:link, a:visited, a:active { text-decoration: none}} /*color of the forum rows*/



    else do this

    .mainrow {font-family: Verdana,Sans-serif;color: #000000;background-color: #F2F2F2;font-size: 12px; a:link, a:visited, a:active { text-decoration: none}} /*color of the forum rows*/

  • #4
    Regular Coder
    Join Date
    May 2008
    Location
    Ohio
    Posts
    231
    Thanks
    3
    Thanked 21 Times in 21 Posts
    PHP Code:
    if($important==1) {
        
    $class "mainrow1";
    } else {
        
    $class "mainrow2";

    Then when you're displaying the html element that's changing color:

    PHP Code:
    echo '<tag class="' $class '">Tag content</tag>'
    Similar code produces this: http://zb3.zoklet.net/globalstats.php

    PHP Code:
    // inside the loop that echoes the alternating colored rows
    $switch 0;
    if(
    $switch == 0){
        echo 
    "<tr align=\"center\" class=\"rowa\">\n";
    } else {
        echo 
    "<tr align=\"center\" class=\"rowb\">\n";
    }
    // echo row's contents here
    // and here
    echo '</tr>';
    $switch++; 
    zok@zoklet:~$ whereis zok
    zok: http://zoklet.net | http://zoklet.net/otg | /derzok/at/gmail/dot/com

  • #5
    Regular Coder
    Join Date
    Nov 2006
    Posts
    601
    Thanks
    1
    Thanked 2 Times in 2 Posts
    ahhh yes didnt think of doing it that way! ty


  •  

    Posting Permissions

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