duanjue2576 2014-04-18 01:55
浏览 21

加速PHP渲染巨大的选择列表

You guys have been awesome.

My script goes and selects ALL 8500 customers from MYSQL, which in MySQL workbench, takes about 0.16 seconds, which is fine, but it takes the browser 10 seconds to render the box from the results.

Is there a faster way to create this huge select box?

I'm stumped because I thought all the PHP was made on the server side and cannot be sped up.

<body>
<select name="customer" id="customer" onChange="getcustinfo();" data-placeholder="Choose a Customer" class="chosen-select" style="width:500px;" tabindex="1">
<option value=""></option>
<?php // get the products
    $sql = "
        SELECT *
        FROM `cust`
        LEFT Join `address` 
        ON `cust`.`custid` = `address`.`addcustid`
        and `address`.`addtype` = 'b'
        WHERE `cust`.`custactive` = 'y'"
    ;
    $result = mysqli_query($con,$sql) or die('Query failed: Could not get list of CLIENTS: ' . mysqli_error($con)); // query
        while ($row = mysqli_fetch_array($result)) {
                foreach ($row as $key => $value){ ${$key} = $value; }
                $space="";
                $endingspaces = 4-(2*strlen($prodid));

                $custname = substr($row['custname'],0,15);
                $address1 = substr($row['address1'],0,15);
                $addcity = substr($row['addcity'],0,15);

                print "<option value=\"$custid\">$custid: $space$custname, $address1, $addcity, $addstate</option>";                                                
        }
?>
</select>
</body>
  • 写回答

2条回答 默认 最新

  • duangai9678 2014-04-18 01:57
    关注

    Cache it. Generate that HTML once and then save it in memory if you can (APC, memcache) or a flat file. Then on subsequent page loads just read it in from the cache and echo it out. much faster.

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助