Welcome Guest, Not a member yet? Register   Sign In
MYSQL variables
#1

[eluser]jstrebel[/eluser]
Hoping to get some help with this:
Code:
$sql = "SET @rank=0;SELECT wins FROM (SELECT @rank:=@rank+1 AS rank, wins,id, Count(*) FROM images GROUP BY id ORDER BY wins DESC) as cl where id=$id";
        $rank = $this->db->query($sql);

result;
Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ';SELECT wins FROM (SELECT @rank:=@rank+1 AS rank, wins,id, Count(*) FROM images ' at line 1

SET @rank=0;SELECT wins FROM (SELECT @rank:=@rank+1 AS rank, wins,id, Count(*) FROM images GROUP BY id ORDER BY wins DESC) as cl where id=194

Cant use SET in CI?

In phpmyadmin it returns correctly.

CI 1.7 mysql 5+ php 5+
#2

[eluser]jstrebel[/eluser]
I tried this
Code:
$this->db->call_function('SET @rank=0');

and got

Code:
A Database Error Occurred

This feature is not available for the database you are using.

Found out i just need to do 2 queries

Code:
$sql = "SELECT rank FROM (SELECT @rank:=@rank+1 AS rank, wins,id, Count(*) FROM images GROUP BY id ORDER BY wins DESC) as cl where id=$id";
          
        $this->db->query("SET @rank=0");
          $rank = $this->db->query($sql);

any way to do it in one?




Theme © iAndrew 2016 - Forum software by © MyBB