CodeIgniter Forums

Full Version: mysql query mess help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

El Forum

Can you shows us your tables structure ?