Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: Show values in different colours

  1. #1
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Show values in different colours

    Hi Folks,

    I have data in MySql that when it is presented on one of my pages I would like text to appear that any number below 72 shows in red.

    Any number = to 72 shows in blue and any number higher than 72 apprears black.

    The page is populated using a file *.css if this info makes any sense.

    Any help in this regard would be most welcome.

    Regards
    Rob

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    This should work for you:

    PHP Code:
    <?php

    function findNumColor($var) {
      if(
    $var 72) {
      return 
    '<font color="Red">72</font>';
      } elseif(
    $var == 72) {
      return 
    '<font color="Blue">72</font>';
      } else {
      return 
    72;
      }
    }

    // below is just an example of how it'd work in sql returning array of data

    while($r mysql_fetch_array$sql )) {
    echo 
    findNumColor($r[Number]);
    }

    ?>
    HTH
    - Josh

  3. #3
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi ,

    Thanks for the prompt reply.

    I have tried to use this example - to no avail.

    I think the code I am looking for has to appear somewhere in the *.css file.
    I am not a coder at all so rely on your expertise here.

    Please could you advise as to where I should put this code an dshould it be in my *.css file?

    Regards
    Rob

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by Rob (SA) View Post
    I have data in MySql (...) The page is populated using a file *.css if this info makes any sense.
    Is your data coming from a MySQL database or from a css file?
    If the data is coming from a database, are the numbers you are looking for in their own cells, or are they mixed in with other content?

    This will affect how you have to find the content, before you can plug them into JShor's function.

    JShor:
    I think you meant:
    PHP Code:
    <?php

    function findNumColor($var) {
      if(
    $var 72) {
      return 
    '<font color="Red">'.$var.'</font>';
      } elseif(
    $var == 72) {
      return 
    '<font color="Blue">'.$var.'</font>';
      } else {
      return 
    $var;
      }
    }
    ?>
    yeah?

  5. #5
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    How does data come from a css file?

    && yeah, exactly like you said, if the data where the numbers are coming from are mixed with strings and not an integer, the function won't work.

    You should post the code and we'll better understand your dilemma and may be able to help you.
    - Josh

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by JShor View Post
    How does data come from a css file?
    well, that's part of why I was confused. When I read
    Quote Originally Posted by Rob (SA)
    The page is populated using a file *.css if this info makes any sense.
    I thought, maybe he meant css components stored in a database? or maybe he's writing a css page or inline stylesheet?

  7. #7
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi Folks,

    The file i am tryin gto influence can be seen at http://www.gnjgf.co.za/stevie/doom1.php

    The data is found in MySql and the look is determined by info in a css file.

    I will try send the css file:


    Code:
    BODY  { BACKGROUND-COLOR: #ffffff; COLOR: #00008B; font-family: Verdana; font-size: 11px; }
    
    A:link { font-family: Verdana; font-size: 11px; color: #810000; font-weight : bold; TEXT-DECORATION: none; }
    A:visited { font-family: Verdana; font-size: 11px; color: #810000; font-weight : bold; TEXT-DECORATION: none; }
    A:active { font-family: Verdana; font-size: 11px; color: #000000; font-weight : bold; TEXT-DECORATION: none; }
    A:hover { font-family: Verdana; font-size: 11px; color: #FF0000; font-weight : bold; TEXT-DECORATION: overline underline; }
    
    .menu-player {
    	COLOR: #00008B; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 8pt; FONT-VARIANT: small-caps; TEXT-DECORATION: none
    }
    .menu-player:hover {
    									 	COLOR: #cc0000
    }
    .menu {
    	COLOR: #00008B; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; FONT-SIZE: 8pt; FONT-VARIANT: small-caps; FONT-WEIGHT: bold; TEXT-DECORATION: none
    }
    .menu:hover {
    	COLOR: #cc0000
    }
    .menu-bg-player {
    	BACKGROUND-COLOR: #FFFF00; BORDER-BOTTOM: #003366 1px solid; BORDER-LEFT: #003366 1px solid; BORDER-RIGHT: #003366 1px solid; BORDER-TOP: #003366 1px solid; MARGIN: 1px 1px 5px; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px
    em.special { color: red; background: white; }
    normal text <em class="special">72</em> normal text 
    
    }
    .menu-bg {
    	BACKGROUND-COLOR: #E4EEFC; BORDER-BOTTOM: #97BEF4 1px solid; BORDER-LEFT: #97BEF4 1px solid; BORDER-RIGHT: #97BEF4 1px solid; BORDER-TOP: #97BEF4 0px solid; MARGIN: 1px 1px 1px; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px
    }
    
    .menu-bg2 {
    	BACKGROUND-COLOR: #97BEF4; BORDER-BOTTOM: #97BEF4 1px solid; BORDER-LEFT: #97BEF4 1px solid; BORDER-RIGHT: #97BEF4 1px solid; BORDER-TOP: #97BEF4 1px solid; MARGIN: 1px 1px 1px; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px
    }
    
    .title {
    	BACKGROUND-COLOR: #E8E8E8; COLOR: #ffffff; FONT-VARIANT: small-caps; TEXT-TRANSFORM: capitalize
    }
    .title2 {
    	BACKGROUND-COLOR: #00008B; COLOR: #ffffff
    }
    
    .disabled {
    	BACKGROUND-COLOR: #6600ff; COLOR: #ffffff; FONT-VARIANT: small-caps; TEXT-TRANSFORM: capitalize
    }
    
    INPUT { color : #000000; font-family : Verdana; font-size : 10px; font-weight : normal; text-indent : 2px; }
    
    SELECT { background-color : transparent; color : #000000; font-family : Verdana; font-size : 9px; font-weight: normal; text-indent : 1px; }
    
    H1 { font-family: Verdana; font-size: 20px; color: #333333; }
    
    H2 { font-family: Verdana; font-size: 15px; color: #666666; }
    
    td 
    { 
    vertical-align: top; font-family: Verdana; font-size: 11px; color: #000000;
    } 
    
    .error { font-family: Verdana; font-size: 11px; color: #FF0000; font-weight: bold; }
    
    td.alarm
    {
    font-size:10px;
    }
    
    INPUT.main
    {}
    
    .heading {
    	COLOR: #00008B; FONT-SIZE: 12pt; FONT-VARIANT: small-caps; FONT-WEIGHT: bold; MARGIN: 3px 3px 3px 0px; PADDING-BOTTOM: 3px; PADDING-LEFT: 0px; PADDING-RIGHT: 3px; PADDING-TOP: 3px
    }
    
    .bg0 {font-weight : bold; background-color: #B6C2BE; color:#395D4A;}
    .bg1 {font-weight : bold; background-color: #E0FFFF;}
    .bg2 {background-color: #D8E2DF;}
    .bg3 {background-color: #ffffff;}
    .bg4 {background-color: #EDE2A5;}
    .bg5 {background-color: #ffffab;}
    .bg6 {background-color: #BDBEBD;}
    .bg7 {background-color: #EEF2F2;}
    .bg8 {background-color: #31659C;}
    .bgF {background-color: #FDFCA2;}
    .bgP {background-color: #AEB8F6;}
    .bgH {background-color: #B5DBC3;}
    
    
    TABLE   { border-collapse: collapse }
    TR#row1 { border-top: 3px solid black }
    TR#row2 { border-top: 1px solid black }
    TR#row3 { border-top: 1px solid black }
    I hope this helps in getting to a result.

    Perhaps while your busy you might also be able to make suggestion that when I retreive data from MySql the rows that do no have any data but the name and the rank are not to show in the above link.

    Thanks again for your help
    Last edited by Snookerman; 08-31-2009 at 06:01 AM.

  8. #8
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    This is extremely confusing. Can you post the PHP code for us?

    PHP code starts with "<?php" and ends with "?>". From there, we can work on it.

    Also, if I can comment, I've never seen HTML mixed in CSS code before, like this
    Code:
    MARGIN: 1px 1px 5px; PADDING-BOTTOM: 1px; PADDING-LEFT: 1px; PADDING-RIGHT: 1px; PADDING-TOP: 1px
    em.special { color: red; background: white; }
    normal text <em class="special">72</em> normal text
    is that even valid?
    - Josh

  9. #9
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    PHP Code:
    <?php

    $scores 
    = array(
        array(
    69787290887066),
        array(
    69787290887066),
        array(
    69787290887066),
        array(
    69787290887066),
        );

    function 
    scoreClass($score) {
        return 
    $score 72 'below' : ($score 72 'above' 'par');
    }

    ?>
    <html>
        <head>
        <style>
        .below { color: red; }
        .par { color: blue; }
        .above { color: black; }
        </style>
        </head>
        <body>
        <table>
            <?php foreach($scores as $scoresArray): ?>
            <tr>
                <?php foreach($scoresArray as $score): ?>
                <td class="<?= scoreClass($score?>"><?= $score?></td>
                <?php endforeach; ?>
            </tr>
            <?php endforeach; ?>
        </table>
        </body>
    </html>
    This is just to get you started. You will need to put the function into your page. Then you'll need to call it in the loop you are using to build all your table rows.

    Your loop is going to be a little complicated as you don't want to be placing class="par" in the td tags that hold the rank or person's name.

    The css you have is a huge mess. You should move all of it to an external file. Instead of putting css into every td tag, you can put one line either in the page head section or an external file, etc...

    EDIT: I just read the part of your post where you say that you are not a coder, which might mean you are a designer? If that is the case and you don't have any interest in coding, you probably should find/hire someone to do the php. I could see this getting pretty complicated for you as the example I gave is not going to get you very far if you don't have any coding experience or aren't interested in coding. If you are interested in coding and learning, that is something entirely different. If this is the case, then keep asking your questions.
    Last edited by JasonDFR; 08-31-2009 at 08:55 AM. Reason: Read that the op is not a coder

  10. #10
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi Folks,

    Thank you for your replies.

    I am very keen to learn the processes and am by no means a designer or coder.

    I am a parent who is volintarily trying to learn all these methods of coding, script writting, php etc so that I may put a website together for the improvement of junior golf.

    My endevours have led me to this position.

    The idea is to prepare pages that show the results of scores scored in a round of golf and produce stats for them.

    The script I sent you was as I have copied straight from the css file and as for its neatness I cannot explain.

    I thank you for your patience and hope we can work forward in my endevour to learn.


    Code:
    1. <?php
    2. $connect = mysql_connect("localhost", "******_robert", "******") or
    3. die ("Hey loser, check your server connection.");
    4. mysql_select_db("*****_DOOM");
    5. $query="select * from strokeaverage ORDER BY `rank` ASC ";
    6. $result=mysql_query($query) or die(mysql_error());
    7. ?>
    8. <! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
    9. <!------------------------------------------------------------------>
    10. <TITLE></TITLE>
    11. <link rel="StyleSheet" href="style.css" type="text/css">
    12. </HEAD>
    13. <body>
    14. <table width="100%" border="2" cellspacing="0" cellpadding="0" align="center">
    15. <tr align="left" valign="top">
    16. <td class="title">
    17. <table width="100%" border="1" cellspacing="1" cellpadding="2">
    18. </table>
    19. <td>
    20. <tr class="menu-bg"><td colspan=29><b>GAUTENG NORTH JUNIOR GOLF FOUNDATION - DOMESTIC SCORES ONLY&nbsp;</b><a href='startgame.php'>[Click to Organise]</a></td>
    21. </tr>
    22. <tr class="menu-bg"><td>Rank</td><td>Full Name</td><td>D11</td><td>D12</td><td>D13</td><td>D14</td><td>D15</td><td>D16</td>
    23. <td>D17</td><td>D18</td><td>D19</td><td>D20</td><td>D21</td><td>D22</td><td>D23</td><td>D24</td><td>D25</td><td>D26</td>
    24. <td>D27</td><td>D28</td><td>D29</td><td>D30</td><td>D31</td><td>D32</td>
    25. <td>D33</td><td>D34</td><td>D35</td><td>D36</td>
    26. </tr>
    27. <! THIS SECTION CHANGES THE MAIN HEADING >
    28. <!------------------------------------------------------------------>
    29. <caption><b><font style="font-size:16px" color="#00008B" face="Arial">
    30. </font><b><caption>
    31. <!------------------------------------------------------------------->
    32. <! THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE >
    33. <!------------------------------------------------------------------->
    34. <?php
    35. $counter = array();
    36. $last_rank = "";
    37. $firstNAsAString = "";
    38. while($row=mysql_fetch_array($result)){
    39. // THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
    40. //----------------------------------------------------------------------------------------------------
    41. if($i > 0 AND $row['-rank'] != $last_rank){
    42. echo '<tr>
    43. <td colspan="29">&nbsp;</td>
    44. </tr>';
    45. }
    46. // THIS SECTION ADDS HEADINGS
    47. //------------------------------------------------------
    48. if ($row['-rank'] != $last_rank) {
    49. echo '<tr>
    50. <td colspan="29" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial"><b>DOMESTIC STROKE AVERAGES</b></font></td>
    51. </tr>';
    52. echo '<tr>
    53. <td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>RANK</b></font></td>
    54. <td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>FULL NAME</b></font></td>
    55. <td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>D 11</b></font></td>
    56. <td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>D 12</b></font></td> etc etc etc
    57. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    58. echo $row['d32'];
    59. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    60. echo $row['d41'];
    61. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    62. echo $row['d42'];
    63. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    64. echo $row['d51'];
    65. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    66. echo $row['d52'];
    67. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    68. echo $row['d61'];
    69. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    70. echo $row['d62'];
    71. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    72. echo $row['d71'];
    73. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    74. echo $row['d72'];
    75. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    76. echo $row['d81'];
    77. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    78. echo $row['d82'];
    79. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    80. echo $row['d91'];
    81. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    82. echo $row['d92'];
    83. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    84. echo $row['d101'];
    85. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    86. echo $row['d102'];
    87. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    88. echo $row['d111'];
    89. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    90. echo $row['d112'];
    91. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    92. echo $row['d121'];
    93. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    94. echo $row['d122'];
    95. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    96. echo $row['d131'];
    97. echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
    98. echo $row['d132'];
    99. if($row['i_wish_to_play'] != $last_wish_to_play)
    100. {
    101. // the first n words to extract
    102. $n = 4;
    103. // extract the words
    104. $words = explode(" ", $row['i_wish_to_play']);
    105. // chop the words array down to the first n elements
    106. $firstN = array_slice($words, 1, $n-1);
    107. // glue the 3 elements back into a spaced sentence
    108. $firstNAsAString = implode(" ", $firstN);
    109. }
    110. if(!isset($counter[$firstNAsAString]))
    111. $counter[$firstNAsAString] = 0;
    112. else
    113. $counter[$firstNAsAString]++;
    114. $last_wish_to_play = $row['i_wish_to_play'];
    115. $i++;
    116. echo '</td></tr>';
    117. }
    118. echo '</table>';
    119. ?>
    Last edited by Snookerman; 08-31-2009 at 07:50 PM.

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
  •