Welcome Guest, Not a member yet? Register   Sign In
Using MySQL user-defined variables with database class
#1

[eluser]nsbingham[/eluser]
I'm attempting to dynamically create a rank # based on a sort of a column in a table using something like the following:

Code:
SET @rank:0;SELECT *, @rank := @rank + 1 FROM table_name;

CI is throwing a "You have an error in your SQL syntax" whenever I attempt to include the "SET @rank:0" statement in the query.

Code:
$query = $this->db->query("SET @rank:0;SELECT *, @rank := @rank + 1 FROM table_name;");

Has anyone else had success with this or is it even possible to use MySQL user-defined variables with CI's Database Class or ActiveRecord?

I'm needing to do some sorting based on the rank and so that's why I'm trying to avoid creating another column and storing the rank.

Thanks,
Nathan


Messages In This Thread
Using MySQL user-defined variables with database class - by El Forum - 04-19-2010, 01:39 PM
Using MySQL user-defined variables with database class - by El Forum - 04-19-2010, 01:58 PM
Using MySQL user-defined variables with database class - by El Forum - 04-19-2010, 03:00 PM
Using MySQL user-defined variables with database class - by El Forum - 09-21-2010, 02:37 PM
Using MySQL user-defined variables with database class - by El Forum - 09-21-2010, 03:09 PM
Using MySQL user-defined variables with database class - by El Forum - 09-22-2010, 03:54 PM
Using MySQL user-defined variables with database class - by El Forum - 09-23-2010, 07:07 AM
Using MySQL user-defined variables with database class - by El Forum - 09-23-2010, 07:15 AM



Theme © iAndrew 2016 - Forum software by © MyBB