我想知道是否有人可以告诉我如何索引我所做的 MySQL 查询。从只有 120 行的数据库加载需要很长时间。
我的查询是:
$sql = "SELECT firstname, lastname, email, phone, username, password, status,
memberview, statuschangedate FROM csvdata ORDER BY lastname ";
$sth= $DBH->prepare($sql);
$sth->execute();
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
code
}
感谢您的时间!
已编辑----------
这是实际发生的事情 -
$sql = "SELECT firstname, lastname, email, phone, username, password, status, memberview, statuschangedate FROM csvdata ORDER BY lastname ";
$sth= $DBH->prepare($sql);
$sth->execute();
$i = 0;
echo "<table class='alltable'>
<tr class='firsttr' style='background:gray;'>
<td>First Name </td>
<td>Last Name </td>
<td>Email </td>
<td>Phone </td>
<td>Username </td>
<td>Password </td>
<td>Status </td>
<td>Memberview</td>
<td>Status Change Date</td>
<td>#</td>
</tr>
";
$j = 0;
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
$csvfirst = $row;
$csvfirstname = $csvfirst['firstname'];
$csvlastname = $csvfirst['lastname'];
$csvemail = $csvfirst['email'];
$csvphone = $csvfirst['phone'];
$csvusername = $csvfirst['username'];
$csvpassword= $csvfirst['password'];
$csvstatus = $csvfirst['status'];
$csvmemberview = $csvfirst['memberview'];
$csvstatuschange = $csvfirst['statuschangedate'];
$memberfirstnamearray[$j] = $csvfirstname;
$memberlastnamearray[$j] = $csvlastname;
$memberemailarray[$j] = $csvemail;
$memberphonearray[$j] = $csvphone;
$j++;
$i++;
echo "
<tr>
<td>
$csvfirstname
</td>
<td>
$csvlastname
</td>
<td>
$csvemail
</td>
<td>
$csvphone
</td>
<td>
$csvusername
</td>
<td>
$csvpassword
</td>
<td>
$csvstatus
</td>
<td>
$csvmemberview
</td>
<td>
$csvstatuschange
</td>
<td>
$i
</td>
</tr>
";
}
$_SESSION['firstnameexport'] = $memberfirstnamearray;
$_SESSION['lastnameexport'] = $memberlastnamearray;
$_SESSION['emailexport'] = $memberemailarray;
$_SESSION['phoneexport'] = $memberphonearray;
$_SESSION['num'] = $j;
echo "
</table>";
}
因此,它从数据库中抓取了大约 120 名员工,加载大约需要 20 秒。我将这张表包含在div
一个按钮中,一旦你给它计时,jquery 就会visibility: none
变为可见并向下滑动。
需要帮助请叫我!
已编辑----------
从使用 desc csvdata - 这是永远占用的员工。
'id', 'int(11)', 'NO', 'PRI', NULL, 'auto_increment'
'firstname', 'varchar(105)', 'YES', '', NULL, ''
'lastname', 'varchar(105)', 'YES', '', NULL, ''
'email', 'varchar(105)', 'YES', '', NULL, ''
'phone', 'varchar(105)', 'YES', '', NULL, ''
'username', 'varchar(105)', 'YES', '', NULL, ''
'password', 'varchar(105)', 'YES', '', NULL, ''
'status', 'varchar(105)', 'YES', '', NULL, ''
'memberview', 'varchar(105)', 'YES', '', NULL, ''
'statuschangedate', 'varchar(105)', 'YES', '', NULL, ''
'notes', 'varchar(1000)', 'YES', '', NULL, ''
'customernotes', 'varchar(1000)', 'YES', '', NULL, ''