PDA

View Full Version : Show values in different colours



Rob (SA)
08-30-2009, 02:23 PM
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

JShor
08-30-2009, 04:00 PM
This should work for you:



<?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:)

Rob (SA)
08-30-2009, 05:56 PM
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

traq
08-30-2009, 11:22 PM
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

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?

JShor
08-31-2009, 01:49 AM
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.

traq
08-31-2009, 03:11 AM
How does data come from a css file?


well, that's part of why I was confused. When I read

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?

Rob (SA)
08-31-2009, 04:31 AM
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:



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

JShor
08-31-2009, 04:49 AM
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


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?

JasonDFR
08-31-2009, 06:53 AM
<?php

$scores = array(
array(69, 78, 72, 90, 88, 70, 66),
array(69, 78, 72, 90, 88, 70, 66),
array(69, 78, 72, 90, 88, 70, 66),
array(69, 78, 72, 90, 88, 70, 66),
);

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.

Rob (SA)
08-31-2009, 05:55 PM
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.




<?php

$connect = mysql_connect("localhost", "******_robert", "******") or

die ("Hey loser, check your server connection.");

mysql_select_db("*****_DOOM");

$query="select * from strokeaverage ORDER BY `rank` ASC ";
$result=mysql_query($query) or die(mysql_error());

?>
<! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
<!------------------------------------------------------------------>

<TITLE></TITLE>
<link rel="StyleSheet" href="style.css" type="text/css">
</HEAD>
<body>
<table width="100%" border="2" cellspacing="0" cellpadding="0" align="center">
<tr align="left" valign="top">
<td class="title">
<table width="100%" border="1" cellspacing="1" cellpadding="2">
</table>

<td>
<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>
</tr>
<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>
<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>
<td>D27</td><td>D28</td><td>D29</td><td>D30</td><td>D31</td><td>D32</td>
<td>D33</td><td>D34</td><td>D35</td><td>D36</td>
</tr>

<! THIS SECTION CHANGES THE MAIN HEADING >
<!------------------------------------------------------------------>
<caption><b><font style="font-size:16px" color="#00008B" face="Arial">
</font><b><caption>
<!------------------------------------------------------------------->
<! THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE >
<!------------------------------------------------------------------->
<?php
$counter = array();
$last_rank = "";
$firstNAsAString = "";
while($row=mysql_fetch_array($result)){

// THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
//----------------------------------------------------------------------------------------------------
if($i > 0 AND $row['-rank'] != $last_rank){
echo '<tr>
<td colspan="29">&nbsp;</td>
</tr>';
}

// THIS SECTION ADDS HEADINGS
//------------------------------------------------------
if ($row['-rank'] != $last_rank) {
echo '<tr>
<td colspan="29" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial"><b>DOMESTIC STROKE AVERAGES</b></font></td>
</tr>';
echo '<tr>

<td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>RANK</b></font></td>
<td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>FULL NAME</b></font></td>
<td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>D 11</b></font></td>
<td align="center" bgcolor="#D6D6D8"><font style="font-size:8px" color="#00008B" face="Arial"><b>D 12</b></font></td>

etc etc etc



echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d32'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d41'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d42'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d51'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d52'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d61'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d62'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d71'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d72'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d81'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d82'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d91'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d92'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d101'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d102'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d111'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d112'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d121'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d122'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d131'];
echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['d132'];
if($row['i_wish_to_play'] != $last_wish_to_play)
{
// the first n words to extract
$n = 4;
// extract the words
$words = explode(" ", $row['i_wish_to_play']);
// chop the words array down to the first n elements
$firstN = array_slice($words, 1, $n-1);
// glue the 3 elements back into a spaced sentence
$firstNAsAString = implode(" ", $firstN);
}
if(!isset($counter[$firstNAsAString]))
$counter[$firstNAsAString] = 0;
else
$counter[$firstNAsAString]++;
$last_wish_to_play = $row['i_wish_to_play'];
$i++;
echo '</td></tr>';
}
echo '</table>';
?>

Rob (SA)
08-31-2009, 06:04 PM
Hi ,

This section is also incorrect

if($i > 0 AND $row['-rank'] != $last_rank){
echo '<tr>
<td colspan="29">&nbsp;</td>
</tr>';

But if if I change the '-rank' to 'rank' it does wierd things to what i actually want the page to look like howevr if I remove it all it has a negative impact on my efforts hence me leaving it there.

Regards
Rob

JShor
08-31-2009, 08:21 PM
OK. It could be that the page isn't processing the integer, thus, the function does not work. Using intval() could do the trick.

As for that line of code, you can also add a negative sign BEFORE the variable to make the number a negative number [if indeed that's what you're trying to accomplish]. Then, use intval() to process it as an integer.

Here's the revised code for you, hopefully, should work for you;


<?php

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

$connect = mysql_connect("localhost", "******_robert", "******") or

die ("Hey loser, check your server connection.");

mysql_select_db("*****_DOOM");

$query="select * from strokeaverage ORDER BY `rank` ASC ";

$result=mysql_query($query) or die(mysql_error());

?>

<! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >

<!------------------------------------------------------------------>

<TITLE></TITLE>

<link rel="StyleSheet" href="style.css" type="text/css">

</HEAD>

<body>

<table width="100%" border="2" cellspacing="0" cellpadding="0" align="center">

<tr align="left" valign="top">

<td class="title">

<table width="100%" border="1" cellspacing="1" cellpadding="2">

</table>

<td>

<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>

</tr>

<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>

<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>

<td>D27</td><td>D28</td><td>D29</td><td>D30</td><td>D31</td><td>D32</td>

<td>D33</td><td>D34</td><td>D35</td><td>D36</td>

</tr>

<! THIS SECTION CHANGES THE MAIN HEADING >

<!------------------------------------------------------------------>

<caption><b><font style="font-size:16px" color=" 00008B" face="Arial">

</font><b><caption>

<!------------------------------------------------------------------->

<! THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE >

<!------------------------------------------------------------------->

<?php

$counter = array();

$last_rank = "";

$firstNAsAString = "";

while($row=mysql_fetch_array($result)){

if($i > 0 && intval(-$row['rank']) != $last_rank){

echo '<tr>

<td colspan="29">&nbsp;</td>

</tr>';

}

echo '<tr>

<td align="center" bgcolor=" D6D6D8"><font style="font-size:8px" color=" 00008B" face="Arial"><b>RANK</b></font></td>

<td align="center" bgcolor=" D6D6D8"><font style="font-size:8px" color=" 00008B" face="Arial"><b>FULL NAME</b></font></td>

<td align="center" bgcolor=" D6D6D8"><font style="font-size:8px" color=" 00008B" face="Arial"><b>D 11</b></font></td>

<td align="center" bgcolor=" D6D6D8"><font style="font-size:8px" color=" 00008B" face="Arial"><b>D 12</b></font></td> etc etc etc

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d32']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($findNumColor($row['d41']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d42']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d51']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d52']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d61']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d62']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d71']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d72']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d81']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d82']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d91']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d92']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d101']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d102']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d111']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d112']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d121']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d122']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d131']);

echo '</td><td align="center" bgcolor=" FFFFFF"><font style="font-size:10px" color=" 00008B" face="Arial">';

echo findNumColor($row['d132']);

if($row['i_wish_to_play'] != $last_wish_to_play)

{

// the first n words to extract

$n = 4;

// extract the words

$words = explode(" ", $row['i_wish_to_play']);

// chop the words array down to the first n elements

$firstN = array_slice($words, 1, $n-1);

// glue the 3 elements back into a spaced sentence

$firstNAsAString = implode(" ", $firstN);

}

if(!isset($counter[$firstNAsAString]))

$counter[$firstNAsAString] = 0;

else

$counter[$firstNAsAString]++;

$last_wish_to_play = $row['i_wish_to_play'];

$i++;

echo '</td></tr>';

}

echo '</table>';

?>


HTH:)

Rob (SA)
08-31-2009, 08:32 PM
Hi,

Thanks for the reply.

I have seen that if I give the values a negative value then the text colour could change but in terms of my exercise the values need to be positive.

The -rank was something i fiddled with and it removed the effect that it caused when not haveing the negative value added.

If I understand correctly then - the values shown in blue, green and red below are what should be changed in my php file?

I appreciate your time

Regards
Rob

JShor
08-31-2009, 09:01 PM
That's exactly right, those values need to be changed in your script.

As for the -rank, you can't have a negative field of anything, even if in mysql it's an integer. If that's the problem, then leave it as a positive int, only.

HTH:)

Rob (SA)
08-31-2009, 09:11 PM
Hi,

Thanks it works great.

You can see the changes at www.gnjgf.co.za/stevie/doom1.php

Last question - if I may

The page populates rows that have no numbers and this is thus useless info.

How do I go about inserting a line that would thus ignore the rows if there is no data in the mysql?

Regards
rob:)

JShor
08-31-2009, 11:38 PM
Well, you'd need to do it in php, unfortunately not in MySQL syntax bc you can only have 2 equalities [WHERE//AND], and you've got like a dozen fields.

So, after the while() statement, insert this line of code:


if($row['d32'] != '' && $row['d41'] != '' && $row['d42'] != '' && $row['d51'] != '' && $row['d52'] != '' && $row['d61'] != '' && $row['d62'] != '' && $row['d71'] != '' && $row['d72'] != '' && $row['d81'] != '' && $row['d82'] != '' && $row['d91'] != '' && $row['d92'] != '' && $row['d101'] != '' && $row['d111'] != '' && $row['d112'] != '' && $row['d121'] != '' && $row['d122'] != '' && $row['d131'] != '' && $row['d132']) {


and then, after this line of code ... :


echo '</td></tr>';


you'll need to insert the terminating curly bracket to close the IF statement:


}


HTH:)

Rob (SA)
09-01-2009, 04:40 AM
Hi,

Thanks for the reply.

I will take some time to hav a look at it and let you know my success

Regards
Rob

Rob (SA)
09-02-2009, 08:38 AM
Hi Folks,

Not succesful due to having several if staements and not knowing exactly where the end of the while staemetns are that are specifc to this task.

Your assitance here is requested.

Regards
Rob

JShor
09-02-2009, 03:20 PM
Sorry to hear Rob. If you paste your entire page's php code, I'll implement it easy.

Rob (SA)
09-02-2009, 03:29 PM
Hi,

Thanks for the reply

It the way things go when i am learning.

[COLOR="Blue"]
<?php

//------------------------------------------------------------------>
// THIS SECTION CHANGES THE VALUES of <72 TO RED and PAR TO BLUE >
// >
// INCLUDING THIS BELOW echo findNumColor($row['d11']); >
//------------------------------------------------------------------>

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

$connect = mysql_connect("localhost", "******_robert", "**********") or

die ("Hey loser, check your server connection.");

mysql_select_db("*********_DOOM");

$query="select * from strokeaverage ORDER BY `rank` ASC ";
$result=mysql_query($query) or die(mysql_error());

?>
<!------------------------------------------------------------------>
<! THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE >
<!------------------------------------------------------------------>

<TITLE></TITLE>
<link rel="StyleSheet" href="style.css" type="text/css">
</HEAD>
<body>
<table width="100%" border="2" cellspacing="0" cellpadding="1" align="center">
<tr align="center" valign="top">
<td class="title">
<table width="100%" border="1" cellspacing="1" cellpadding="0">
</table>


<td>
<tr class="menu-bg"><td colspan=34><b>SOUTH AFRICAN JUNIOR GOLF FOUNDATION - NATIONAL SCORES ONLY &nbsp;</b></td>
</tr>
<tr class="menu-bg">
<td>Rank</td><td>Full Name</td>
<td>N1A</td><td>N1P</td><td>N2A</td><td>N2P</td><td>N3A</td><td>N3P</td>
<td>N4A</td><td>N4P</td><td>N5A</td><td>N5P</td><td>N6A</td><td>N6P</td>

<td>S81</td><td>S82</td><td>S83</td><td>S84</td>
<td>S61</td><td>S62</td><td>S63</td><td>S64</td>
<td>S41</td><td>S42</td><td>S43</td><td>S44</td>
<td>S21</td><td>S22</td><td>S23</td><td>S24</td>

<td>GN1</td><td>GN2</td><td>GN3</td><td>GN4</td>

</tr>

<!------------------------------------------------------------------>
<! THIS SECTION CHANGES THE MAIN HEADING >
<!------------------------------------------------------------------>
<caption><b><font style="font-size:16px" color="#00008B" face="Arial">
</font><b><caption>
<!------------------------------------------------------------------->
<! THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE >
<!------------------------------------------------------------------->
<?php
$counter = array();
$last_rank = "";
$firstNAsAString = "";
while($row=mysql_fetch_array($result)){

//----------------------------------------------------------------------------------------------------
// THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED
//----------------------------------------------------------------------------------------------------
if($i > 0 AND $row['-rank'] != $last_rank){
echo '<tr>
<td colspan="29">&nbsp;</td>
</tr>';
}
//------------------------------------------------------
// THIS SECTION ADDS HEADINGS
//------------------------------------------------------
if ($row['-rank'] != $last_rank) {
echo '<tr>
<td colspan="29" align="center" bgcolor="#FFFFFF"><font style="font-size:11px" color="#00008B" face="Arial"><b>DOMESTIC STROKE AVERAGES</b></font></td>
</tr>';
echo '<tr>


</tr>';
}

echo '<tr><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['rank'];

echo '</td><td bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo '<option value="'.$row['surname'].', '.$row['name'].'"><b>'.$row['surname'].'</b>, '.$row['name'].'</option>';

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n1a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n1p']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n2a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n2p']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n3a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n3p']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n4a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n4p']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n5a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n5p']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n6a']);

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo findNumColor($row['n6p']);

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s81'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s82'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s83'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s84'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s61'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s62'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s63'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s64'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s41'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s42'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s43'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s44'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s21'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s22'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s23'];

echo '</td><td align="center" bgcolor="#FFFFFF"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['s24'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['gn1'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['gn2'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['gn3'];

echo '</td><td align="center" bgcolor="#F5F5F5"><font style="font-size:10px" color="#00008B" face="Arial">';
echo $row['gn4'];








if($row['i_wish_to_play'] != $last_wish_to_play)
{
// the first n words to extract
$n = 4;
// extract the words
$words = explode(" ", $row['i_wish_to_play']);
// chop the words array down to the first n elements
$firstN = array_slice($words, 1, $n-1);
// glue the 3 elements back into a spaced sentence
$firstNAsAString = implode(" ", $firstN);
}
if(!isset($counter[$firstNAsAString]))
$counter[$firstNAsAString] = 0;
else
$counter[$firstNAsAString]++;
$last_wish_to_play = $row['i_wish_to_play'];

$i++;
echo '</td></tr>';


}
echo '</table>';

?>
[/LIST]

JasonDFR
09-02-2009, 03:56 PM
Before you get guys get carried away, perhaps it is better to look at the database queries being used, then figure out a way to only return the results you want. It would be better to build a query that only returns the data you want, rather than trying to manipulate your result to get rid of bad data.

Rob, perhaps you could post the query you are using. There is this one in your code: $query="select * from strokeaverage ORDER BY `rank` ASC "; Is that it? If so, how is the rank being determined? Are all the scores placed into this table? Also post a description of the table being used to store the data. Is the list of scores on your website basically a representation of the table in the db? If so that means that each time a new match is played somebody is adding a new column and then filling in each person's score? How is the rank calculated?

Rob (SA)
09-02-2009, 04:13 PM
Hi,

Thank you for the interest and understanding of my requirement.

We have previously used an excel spreadsheet to present our averages and rankings. This does not work to well hence the plan to move foward.

The scores are scores from golf games and currently it represnets what is in my table in MySql.

The actula idea is to have this table linked to a page that captures scores to the database.

These scores will then be manipulated by scripts to produce various results.

That is:

The Domestic Averages
The National Averages
The Rankings of all the players
The top 10 players from each age group u18,u16,u14,u12 and girls

The rankings as you see it are the current rankings but are not ranking determined by any script.

I have been busy with the look and feel side and hopefully not chasing myself in the wrong direction.

I look forward to your replies.

Regards
Rob

Rob (SA)
09-02-2009, 04:26 PM
Hi Jason,

I would appreciate any assitance I can get to get tis part of my strokaverages working.

I am at a place which is pretty simple in design at the moment if it helps for you to see what my ideas are:

http://www.gnjgf.co.za/strokeaverage.php

Our current stroke averages ar efound at http://www.gnjgf.co.za/GNJGF_OOM_BOYS.htm

If either of you are keen to develop the entire project you are more than welocme to contact me and we can plan ahead.

Thanks again for all your help

Regards
Rob