访问量一大功能就不能正确实现了,求高手帮忙优化两段PHP代码解决方法
current
mysql
query
quot
访问量一大功能就不能正确实现了,求高手帮忙优化两段PHP代码
第一段:
- PHP code
<!-- 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 "数据库连接错误!"; } //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
<!-- 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加上索引就行了
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

如何修復 MySQL 8.4 上的 mysql_native_password 未載入錯誤
