In doing a statistics page, now encountering such a problem.
such as title: How to find the maximum value of each single column in a two-dimensional array.
, I need to find the maximum value of the single column I want, and then apply the appropriate style.
Now the display effect
Display effects that need to be implemented
The corresponding color CSS Class I have already written, just need to quote on the line.
Do not use JS code, that is, directly in the generation of direct judgment, and then reference style.
Some of the code is as follows:
$index=1; while($row = mysql_fetch_array($result)){ echo ''; echo ''.$index.''; echo ''.$row[user].''; echo ''.$row[speed].''; echo ''.$row[keystroke].''; echo ''.$row[length].''; echo ''.$row[backspace].''; echo ''.$row[wrong].''; echo ''.$row[ime].''; echo ''.$row[wordcount].''; echo ''.$row[timecost].''; echo ''.$row[qq].''; echo ''.date("H:i",strtotime($row[timestart])).''; echo ''.$row[repeat].''; echo ''.$row[score].''; echo ''.$row[scoresum].''; echo ''; $index++; /************************************************ 其中的essential和center没什么其它作用,可以忽略。 ************************************************/ }
To cut into an array of what to say, I just don't know how to make a judgment after depositing the array.
Ask the big God to say the fine point, small white here thanked.
Reply content:
In doing a statistics page, now encountering such a problem.
such as title: How to find the maximum value of each single column in a two-dimensional array.
, I need to find the maximum value of the single column I want, and then apply the appropriate style.
Now the display effect
Display effects that need to be implemented
The corresponding color CSS Class I have already written, just need to quote on the line.
Do not use JS code, that is, directly in the generation of direct judgment, and then reference style.
Some of the code is as follows:
$index=1; while($row = mysql_fetch_array($result)){ echo ''; echo ''.$index.''; echo ''.$row[user].''; echo ''.$row[speed].''; echo ''.$row[keystroke].''; echo ''.$row[length].''; echo ''.$row[backspace].''; echo ''.$row[wrong].''; echo ''.$row[ime].''; echo ''.$row[wordcount].''; echo ''.$row[timecost].''; echo ''.$row[qq].''; echo ''.date("H:i",strtotime($row[timestart])).''; echo ''.$row[repeat].''; echo ''.$row[score].''; echo ''.$row[scoresum].''; echo ''; $index++; /************************************************ 其中的essential和center没什么其它作用,可以忽略。 ************************************************/ }
To cut into an array of what to say, I just don't know how to make a judgment after depositing the array.
Ask the big God to say the fine point, small white here thanked.
Know how to do it, first read each column of data from the database, and then use Max (), Min () to calculate the maximum value of each column
Then, at the time of the output, if the data at the top of the column is equal to the maximum value of the columns, then a special style is given.
One of the things to be aware of is: Mysql_fetch_array can only take one data, after the first time after the inside there is no data. So first the query to the data dump.
Some of the code is as follows:
The result of the dump query $temp _result = Array (); while ($row =mysql_fetch_array ($result)) {Array_push ($temp _result, $row); }//Gets all the data for each column, calculates the maximum value; $speed = Array (); $keystroke = Array (); $length = Array (); $backspace = Array (); $repeat = Array (); foreach ($temp _result as $row) {Array_push ($speed, $row [speed]); Array_push ($keystroke, $row [keystroke]); Array_push ($length, $row [length]); Array_push ($backspace, $row [backspace]); Array_push ($repeat, $row [repeat]); } $max _speed=max ($speed); $max _keystroke=max ($keystroke); $min _length = min ($length); $min _backspace = min ($backspace); $max _repeat = max ($repeat); Output list $index = 1; foreach ($temp _result as $row) {echo ''; Echo ''. $index. ''; Echo ''. $row [user]. ''; if ($row [speed]== $max _speed) {echo ''. $row [speed]. ''; }else{Echo ''. $row [speed]. ''; if ($row [keystroke]== $max _keystroke) {echo ''. $row [keystroke]. ''; }else{Echo ''. $row [keystroke]. ''; if ($row [length]== $min _length) {echo ''. $row [length]. ''; }else{Echo ''. $row [length]. ''; if ($row [backspace]== $min _backspace) {echo ''. $row [backspace]. ''; }else{Echo ''. $row [backspace]. ''; } Echo ''. $row [wrong]. ''; Echo ''. $row [wordcount]. ''; Echo ''. $row [timecost]. ''; Echo ''. Date ("M-d h:i", Strtotime ($row [Timestart])). ''; if ($row [repeat]== $max _repeat) {echo ''. $row [repeat]. ''; }else{Echo ''. $row [repeat]. ''; } Echo ''. $row [score]. ''; Echo ''. $row [scoresum]. ''; Echo ''; $index + +; }
The final display effect