Welcome Guest, Not a member yet? Register   Sign In
mysql query mess help
#1

[eluser]quasiperfect[/eluser]
can anyone sugest a more elegant method of doing this
Code:
$this->db->query("CREATE TEMPORARY TABLE ranks (rank int(10) NOT NULL,voted VARCHAR(15) NOT NULL) ENGINE=MEMORY");
$this->db->query("INSERT INTO ranks (rank, voted) select @rownum:=@rownum+1 as rank,voted from (select @rownum:=0,votes.voted, (sum(votes.vote)) as score,count(votes.id) as nr_votes from votes,users where votes.date like '".date("Y-m")."%' and votes.contest = ".$this->db->escape($contest)." and votes.sex = ".$this->db->escape($sex)." and users.deleted = 'no' and users.rights = 'normal' and users.username = votes.voted GROUP BY votes.voted ORDER BY score desc,nr_votes desc,users.subscription desc) as r");
$query = $this->db->query("select rank from ranks where voted = " . $this->db->escape($username));
$this->db->query("DROP TABLE ranks");

?

the idea is to select the rank of a user


Messages In This Thread
mysql query mess help - by El Forum - 04-15-2011, 05:07 AM
mysql query mess help - by El Forum - 04-15-2011, 07:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB