-
Hi ,
This section is also incorrect
if($i > 0 AND $row['-rank'] != $last_rank){
echo '<tr>
<td colspan="29"> </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
-
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 Code:
<?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 </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"> </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:)
-
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
-
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:)
-
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:)
-
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:
PHP 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 ... :
PHP Code:
echo '</td></tr>';
you'll need to insert the terminating curly bracket to close the IF statement:
HTH:)
-
Hi,
Thanks for the reply.
I will take some time to hav a look at it and let you know my success
Regards
Rob
-
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
-
Sorry to hear Rob. If you paste your entire page's php code, I'll implement it easy.
-
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 </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"> </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]