CodeIgniter Forums
mysql query mess help - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: mysql query mess help (/thread-40665.html)

mysql query mess help - El Forum - 04-15-2011

can anyone sugest a more elegant method of doing this
$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:[email protected]+1 as rank,voted from (select @rownum:=0,votes.voted, (sum( as score,count( as nr_votes from votes,users where like '".date("Y-m")."%' and votes.contest = ".$this->db->escape($contest)." and = ".$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

mysql query mess help - El Forum - 04-15-2011

Can you shows us your tables structure ?