在做一个统计网页,现在遇到这样一个问题。
如标题:怎么在二维数组中,找到每个单列的最值。
如图,我需要找到需要的单列的最值,然后应用相应的样式。
现在的显示效果
需要实现的显示效果
相应的颜色css类我已经写好了,只需要引用就行了。
不用js代码,也就是说直接在生成的时候直接判断,再引用样式。
部分代码如下:
<code> $index=1; while($row = mysql_fetch_array($result)){ echo '<tr>'; echo '<td class="center essential">'.$index.'</td>'; echo '<td class="essential"><a class="user" href="search.php?qq='.%24row%5Bqq%5D.'&user='.%24row%5Buser%5D.'">'.$row[user].'</a></td>'; echo '<td class="essential">'.$row[speed].'</td>'; echo '<td class="essential">'.$row[keystroke].'</td>'; echo '<td class="essential">'.$row[length].'</td>'; echo '<td class="essential">'.$row[backspace].'</td>'; echo '<td>'.$row[wrong].'</td>'; echo '<td class="center">'.$row[ime].'</td>'; echo '<td class="center">'.$row[wordcount].'</td>'; echo '<td class="center">'.$row[timecost].'</td>'; echo '<td>'.$row[qq].'</td>'; echo '<td class="center">'.date("H:i",strtotime($row[timestart])).'</td>'; echo '<td class="center">'.$row[repeat].'</td>'; echo '<td>'.$row[score].'</td>'; echo '<td>'.$row[scoresum].'</td>'; echo '</tr>'; $index++; /************************************************ 其中的essential和center没什么其它作用,可以忽略。 ************************************************/ }</code>
切成数组什么的好说,我只是不知道存入数组后如何才能进行判断。
求大神说的细点,小白在此谢过。
回复内容:
在做一个统计网页,现在遇到这样一个问题。
如标题:怎么在二维数组中,找到每个单列的最值。
如图,我需要找到需要的单列的最值,然后应用相应的样式。
现在的显示效果
需要实现的显示效果
相应的颜色css类我已经写好了,只需要引用就行了。
不用js代码,也就是说直接在生成的时候直接判断,再引用样式。
部分代码如下:
<code> $index=1; while($row = mysql_fetch_array($result)){ echo '<tr>'; echo '<td class="center essential">'.$index.'</td>'; echo '<td class="essential"><a class="user" href="search.php?qq='.%24row%5Bqq%5D.'&user='.%24row%5Buser%5D.'">'.$row[user].'</a></td>'; echo '<td class="essential">'.$row[speed].'</td>'; echo '<td class="essential">'.$row[keystroke].'</td>'; echo '<td class="essential">'.$row[length].'</td>'; echo '<td class="essential">'.$row[backspace].'</td>'; echo '<td>'.$row[wrong].'</td>'; echo '<td class="center">'.$row[ime].'</td>'; echo '<td class="center">'.$row[wordcount].'</td>'; echo '<td class="center">'.$row[timecost].'</td>'; echo '<td>'.$row[qq].'</td>'; echo '<td class="center">'.date("H:i",strtotime($row[timestart])).'</td>'; echo '<td class="center">'.$row[repeat].'</td>'; echo '<td>'.$row[score].'</td>'; echo '<td>'.$row[scoresum].'</td>'; echo '</tr>'; $index++; /************************************************ 其中的essential和center没什么其它作用,可以忽略。 ************************************************/ }</code>
切成数组什么的好说,我只是不知道存入数组后如何才能进行判断。
求大神说的细点,小白在此谢过。
知道怎么弄了, 先从数据库把每列的数据先读取出来,然后用max(),min()计算每列的最值
然后,在输出的时候,当前列的数据是否等于这一列的最值,等于的话就给予特殊样式。
其中需要注意的一项是:mysql_fetch_array只能取一次数据,取完一次之后里面就没有数据了。所以先把查询到的数据转存。
部分代码如下:
<code> //转存查询的结果 $temp_result = array(); while($row=mysql_fetch_array($result)){ array_push($temp_result, $row); } //获取每个列的所有数据,算出最值; $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); // 输出列表 $index=1; foreach ($temp_result as $row ) { echo '<tr>'; echo '<td class="center essential">'.$index.'</td>'; echo '<td class="essential"><a class="user" href="search.php?qq='.%24row%5Bqq%5D.'&user='.%24row%5Buser%5D.'">'.$row[user].'</a></td>'; if($row[speed]==$max_speed){ echo '<td class="essential bg-yellow">'.$row[speed].'</td>'; }else{ echo '<td class="essential">'.$row[speed].'</td>'; } if($row[keystroke]==$max_keystroke){ echo '<td class="essential bg-green">'.$row[keystroke].'</td>'; }else{ echo '<td class="essential">'.$row[keystroke].'</td>'; } if($row[length]==$min_length){ echo '<td class="essential bg-red">'.$row[length].'</td>'; }else{ echo '<td class="essential">'.$row[length].'</td>'; } if($row[backspace]==$min_backspace){ echo '<td class="essential bg-blue">'.$row[backspace].'</td>'; }else{ echo '<td class="essential">'.$row[backspace].'</td>'; } echo '<td>'.$row[wrong].'</td>'; echo '<td class="center">'.$row[wordcount].'</td>'; echo '<td class="center">'.$row[timecost].'</td>'; echo '<td class="center">'.date("m-d H:i",strtotime($row[timestart])).'</td>'; if($row[repeat]==$max_repeat){ echo '<td class="center bg-green">'.$row[repeat].'</td>'; }else{ echo '<td class="center">'.$row[repeat].'</td>'; } echo '<td>'.$row[score].'</td>'; echo '<td>'.$row[scoresum].'</td>'; echo '</tr>'; $index++; }</code>
最终的显示效果

Load balancing affects session management, but can be resolved with session replication, session stickiness, and centralized session storage. 1. Session Replication Copy session data between servers. 2. Session stickiness directs user requests to the same server. 3. Centralized session storage uses independent servers such as Redis to store session data to ensure data sharing.

Sessionlockingisatechniqueusedtoensureauser'ssessionremainsexclusivetooneuseratatime.Itiscrucialforpreventingdatacorruptionandsecuritybreachesinmulti-userapplications.Sessionlockingisimplementedusingserver-sidelockingmechanisms,suchasReentrantLockinJ

Alternatives to PHP sessions include Cookies, Token-based Authentication, Database-based Sessions, and Redis/Memcached. 1.Cookies manage sessions by storing data on the client, which is simple but low in security. 2.Token-based Authentication uses tokens to verify users, which is highly secure but requires additional logic. 3.Database-basedSessions stores data in the database, which has good scalability but may affect performance. 4. Redis/Memcached uses distributed cache to improve performance and scalability, but requires additional matching

Sessionhijacking refers to an attacker impersonating a user by obtaining the user's sessionID. Prevention methods include: 1) encrypting communication using HTTPS; 2) verifying the source of the sessionID; 3) using a secure sessionID generation algorithm; 4) regularly updating the sessionID.

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1
Powerful PHP integrated development environment
