php改进数据检索

1l5u6lss  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(334)

我正在我的mysql数据库中检索5000多个数据。我需要5-10分钟来检索数据(只有在通过网络时,它只是本地速度较慢)有没有办法不使用插件来提高速度?

$ContactID = $_GET["Contact"];

    $sql = "SELECT * FROM tblContacts WHERE Coordinator = '$ContactID'";
    $result = mysqli_query($conn, $sql);
    $count = mysqli_num_rows($result);

    if($count > 0){
        while ($row = mysqli_fetch_array($result)) {
            $supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
            $mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
            $ar[] = array(
                'ContactID' => $row['ContactID'],
                'FileAs' => $row['FileAs'],
                'FirstName' => $row['FirstName'],
                'MiddleName' => $row['MiddleName'],
                'LastName' => $row['LastName'],
                'Position' => $row['Position'],
                'Company' => $row['Company'],
                'CompanyID' => $row['CompanyID'],
                'ContactType' => $row['ContactType'],
                'RetailerType' => $row['RetailerType'],
                'PresStreet' => $row['PresStreet'],
                'PresBarangay' => $row['PresBarangay'],
                'PresDistrict' => $row['PresDistrict'],
                'PresTown' => $row['PresTown'],
                'PresProvince' => $row['PresProvince'],
                'PresCountry' => $row['PresCountry'],
                'Landmark' => $row['Landmark'],
                'Telephone1' => $row['Telephone1'],
                'Telephone2' => $row['Telephone2'],
                'Mobile' => $row['Mobile'],
                'Email' => $row['Email'],
                'Employee' => $row['Employee'],
                'Customer' => $row['Customer'],
                'Coordinator' => $row['Coordinator'],
                'ServerUpdate' => $supdate,
                'MobileUpdate' => $mupdate
            );
        }

        print json_encode($ar);
    }
a6b3iqyw

a6b3iqyw1#

$ContactID = $_GET["Contact"];
$ar = array();
$sql = "SELECT ContactID,FileAs, FirstName ,MiddleName ,LastName ,Position ,Company ,CompanyID  ,ContactType ,RetailerType ,PresStreet 
             ,PresBarangay ,PresDistrict  ,PresTown , PresProvince  ,PresCountry ,Landmark   ,Telephone1 , Telephone2  ,Mobile 
              ,Email  ,Employee  ,Customer  ,Coordinator  FROM tblContacts WHERE Coordinator = '$ContactID'";
$result = mysqli_query($conn, $sql);
$count = mysqli_num_rows($result);

if($count > 0){
    $rowCount = 0;
    while ($row = mysqli_fetch_array($result)) {
        $supdate = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
        $mupdate = date("Y-m-d h:i", strtotime($row['MobileUpdate']));
        $ar[$rowCount] = $row;
        $ar[$rowCount]['ServerUpdate'] = $supdate;
        $ar[$rowCount]['ServerUpdate']  = $mupdate;
         $rowCount++;
    }

    print json_encode($ar);
}

必须首先在顶部声明数组的变量。
您可以直接从mysql调用所需的数据。希望能有所帮助。

vohkndzv

vohkndzv2#

可能是这样的。

$contactID = $_GET["Contact"];
$sql = "SELECT * FROM tblContacts WHERE Coordinator = '$contactID'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0){
    $data = array();
    while($row = mysqli_fetch_array($result)){

        $row['supdate'] = date("Y-m-d h:i", strtotime($row['ServerUpdate']));
        $row['supdate'] = date("Y-m-d h:i", strtotime($row['MobileUpdate']));

        $data[] = $row;
    }
    print json_encode($data);
}

为多个记录更新

相关问题