Access to a large function can not be implemented correctly, ask the master to help optimize two pieces of PHP code solution

Source: Internet
Author: User
Access to a large function can not be implemented correctly, ask the master to help optimize two pieces of PHP code
First paragraph:
PHP Code
  
   
  
   

Second paragraph:
PHP code
!--code highlighting produced by Actipro Codehighlig Hter (freeware) http://www. codehighlighter.com/-->!--? Php@session_start ();d ate_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 Database Gator This sentence} else{echo "Database connection Error!";} $bijiao = "Select Max (Mostcount) from online"; [email& #160;p rotected]_query ($bijiao, $link _id); $most = Intval (@mysql_result ($max, 0)); $time = "Select time from online where mostcount= ' $most '; [email& #160;p rotected]_query ($time, $link _id); [email& #160;p rotected]_result ($time, 0); $already = "Select Max (mostcount) from record"; [email& #160;p rotected]_query ($already, $link _id); $already = Intval (@mysql_result ($already, 0)); if ($most--> $already    {$query = "insert into record (Mostcount,time) VALUES ('". $most. "', ' $time ')"; [Email protected]_query ($query);}? 


------Solution--------------------
The first and second end algorithms are roughly the same
The second algorithm is a bit of a prank.

If you do max operations on Unindexed current or mostcount, you'll be taking a lot of time
------Solution--------------------
You can index current and mostcount in the database.
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.