SQL optimisation

pull/1/head
root 17 years ago
parent bb92596426
commit 20bd086de1

@ -52,47 +52,29 @@
if(intval($_GET['ccid']) <= 0)
{
echo "<ul>\n";
$res = mysql_query("select distinct `ccid`,`countries`.`name` from `users`,`notary`,`countries` where `listme`='1' and `ccid` > 0 and
`users`.`id`=`notary`.`to` and `ccid`=`countries`.`id` group by `notary`.`to` HAVING SUM(`points`) >= 100
order by `countries`.`name`");
$query = "select * from countries where acount>0 order by `name`";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res))
{
$query = "select sum(`users`.`id`) as `listed` from `users`,`notary`
where `listme`='1' and `ccid` = '$row[ccid]' and `users`.`id`=`notary`.`to`
group by `notary`.`to` HAVING SUM(`points`) >= 100";
$listed = mysql_num_rows(mysql_query($query));
echo "<li><a href='wot.php?id=1&ccid=$row[ccid]'>$row[name] ("._("Listed").": $listed)</a></li>\n";
echo "<li><a href='wot.php?id=1&ccid=$row[id]'>$row[name] ("._("Listed").": $row[acount])</a></li>\n";
}
echo "</ul>\n</li>\n</ul>\n<br>\n";
} elseif(intval($_GET['ccid']) > 0 && intval($_GET['regid']) <= 0 && intval($_GET['locid']) <= 0) {
echo "<ul>\n";
$query = "select distinct `regid`,`regions`.`name` from `users`,`notary`,`regions` where `listme`='1' and `users`.`id`=`notary`.`to` and
`regid`=`regions`.`id` and `users`.`ccid`='".intval($_GET['ccid'])."' group by `notary`.`to`
HAVING SUM(`points`) >= 100 order by `regions`.`name`";
$query = "select * from regions where ccid='".intval($_GET['ccid'])."' and acount>0 order by `name`";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res))
{
$query = "select sum(`users`.`id`) as `listed` from `users`,`notary`
where `listme`='1' and `regid` = '$row[regid]' and `users`.`id`=`notary`.`to`
group by `notary`.`to` HAVING SUM(`points`) >= 100";
$listed = mysql_num_rows(mysql_query($query));
echo "<li><a href='wot.php?id=1&regid=$row[regid]'>$row[name] ("._("Listed").": $listed)</a></li>\n";
echo "<li><a href='wot.php?id=1&regid=$row[id]'>$row[name] ("._("Listed").": $row[acount])</a></li>\n";
}
echo "</ul>\n</li>\n</ul>\n</li>\n</ul>\n<br>\n";
} elseif(intval($_GET['regid']) > 0 && intval($_GET['locid']) <= 0) {
echo "<ul>\n";
$query = "select * from `users`,`notary` where `listme`='1' and `regid`='".intval($_GET['regid'])."' and
`users`.`id`=`notary`.`to` group by `locid` HAVING SUM(`points`) >= 100";
$query = "select * from locations where regid='".intval($_GET['regid'])."' and acount>0 order by `name`";
$res = mysql_query($query);
while($row = mysql_fetch_assoc($res))
{
$loc = mysql_fetch_assoc(mysql_query("select * from `locations` where `id`='$row[locid]'"));
$listed = mysql_num_rows(mysql_query("select * from `users`,`notary` where `listme`='1' and
`locid`='".$row['locid']."' and `locid`!=0 and `users`.`id`=`notary`.`to`
group by `notary`.`to` HAVING SUM(`points`) >= 100"));
if($listed > 0)
echo "<li><a href='wot.php?id=1&locid=$loc[id]'>$loc[name] ("._("Listed").": $listed)</a></li>\n";
echo "<li><a href='wot.php?id=1&locid=$row[id]'>$row[name] ("._("Listed").": $row[acount])</a></li>\n";
}
echo "</ul>\n</li>\n</ul>\n</li>\n</ul>\n<br>\n";
} elseif(intval($_GET['locid']) > 0){

Loading…
Cancel
Save