I made a PHP script which requests information from a MySQL table. If it's correct, it does something, but this script is very slow because there are many rows where it is not correct. Here is the script:
$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++;
}
}
My problem is that it checks every post and not only the user's posts.
Is there some solution to make it faster?
If I remove AND owner ='$var'
from the $posts query, it is very fast.
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
SOLUTED