我制作了一个 PHP 脚本,它从 MySQL 表中请求信息。如果它是正确的,它会做一些事情,但是这个脚本很慢,因为有很多行不正确。这是脚本:
$everypost = mysql_query("SELECT MAX(asd) FROM asd;");
$everypost = mysql_fetch_array($everypost);
$id = $everypost[0];
while ($id > 0 && $i < $var2) {
$id = $id - 1;
$tulajid = $context['user']['id'];
$posts = mysql_query("SELECT * FROM asd WHERE asd='$id' AND owner='$var' GROUP BY(asd);");
$prow = mysql_fetch_array($posts);
if(isset($prow['asd'])) {//If it's correct, so the user is the owner
$i++;
}
}
我的问题是它检查每个帖子,而不仅仅是用户的帖子。有没有办法让它更快?如果我AND owner ='$var'
从 $posts 查询中删除,它会非常快。
CREATE TABLE `asd` (
`asd` int(10) unsigned NOT NULL,
`id_member` mediumint(8) unsigned NOT NULL,
`score` smallint(2) NOT NULL,
`owner` mediumint(8) unsigned NOT NULL,
`log_time` int(10) unsigned NOT NULL,
PRIMARY KEY (`id_msg`,`id_member`),
KEY id_member (`id_member`),
KEY owner (`owner`),
KEY owner_2 (`owner`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
已解决