• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

访问量一大功能就不能正确实现了,求高手帮忙优化两段PHP代码解决方法

php 搞代码 4年前 (2022-01-23) 25次浏览 已收录 0个评论

访问量一大功能就不能正确实现了,求高手帮忙优化两段PHP代码
第一段:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php@session_start();date_default_timezone_set('Asia/Shanghai');$link_id =@ mysql_connect('localhost', 'root', 'password');if ($link_id) {     mysql_select_db('database');     mysql_query("set n<p style="color:transparent">。本文来源gao!%daima.com搞$代*!码网1</p><cite>搞代gaodaima码</cite>ames 'utf8'"); //select 数据库之后加多这一句} else{    echo "数据库连接错误!";}//var_dump($current);$Datetime=date("Y-m-d G:i:s");//获取注册时间,也就是数据写入到用户表的时间$bijiao="select max(current) from online";$max=@mysql_query($bijiao,$link_id);$most= intval( @mysql_result($max,0) );$current= intval($_SESSION['current']);$query="insert into online(current,mostcount,time)  values('".$current."','".$most."','$Datetime')";$result=mysql_query($query);echo $most;?>

第二段:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php@session_start();date_default_timezone_set('Asia/Shanghai');$link_id =@ mysql_connect('localhost', 'root', 'password');if ($link_id) {     mysql_select_db('database');     mysql_query("set names 'utf8'"); //select 数据库之后加多这一句} else{    echo "数据库连接错误!";}$bijiao="select max(mostcount) from online";$max=@mysql_query($bijiao,$link_id);$most= intval( @mysql_result($max,0) );$time="select time from online where mostcount='$most'";$time=@mysql_query($time,$link_id);$time=@mysql_result($time,0);$already="select max(mostcount) from record";$already=@mysql_query($already,$link_id);$already= intval( @mysql_result($already,0) );if($most>$already){    $query="insert into record(mostcount,time)  values('".$most."','$time')";    $result=@mysql_query($query);}?>

——解决方案——————–
第一段与第二端的算法大致相同
第二段的算法有点胡闹

如果你对未加索引的 current 或 mostcount 做 max 操作,势必占用大量的时间
——解决方案——————–
你在数据库中给current和mostcount加上索引就行了


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:访问量一大功能就不能正确实现了,求高手帮忙优化两段PHP代码解决方法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址