php查询MYSQL数据库里的记录并显示出来,怎么样能让速度快点?我平时一直是用mysql_fetch_array($result)函数组织数据。发现数据量大的时候速度会慢下来,不知道大家都怎么查询和显示。听说可以把数据全部查询出来后由JS去组织,这样能把一部分负担分给客户机,这方法可行吗?哪位有这方面的资料?
下面是我常用的显示方法:
$result=mysql_query('select id,username,address,phone from userlist order by id desc');
while ($rs=mysql_fetch_array($result)){
echo $rs["id"].",";
echo $rs["username"].",";
echo $rs["mydate"].";";
}

解决方案 »

  1.   

    試下在MYSQL裡創建索引,個人認為速度很快!
      

  2.   


    <?php
    //这种方法不错.
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world");if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }/* prepare statement */
    if ($stmt = $mysqli->prepare("SELECT Code, Name FROM Country ORDER BY Name LIMIT 5")) {
        $stmt->execute();    /* bind variables to prepared statement */
        $stmt->bind_result($col1, $col2);    /* fetch values */
        while ($stmt->fetch()) {
            printf("%s %s\n", $col1, $col2);
        }    /* close statement */
        $stmt->close();
    }
    /* close connection */
    $mysqli->close();?> 
      

  3.   

    mysql_fetch_array它打印两种方式:一种是关联数组;一种是索引数组如果只需要一结果的话,别用它
      

  4.   

    JS 可以分担服务器的负担,但是主要的时间瓶颈是数据库的查询大量数据,优化数据查询语句是关键,然后使用mysqli_prepare系列函数 应该也可以提高一点效率